Skip to main content

Handling lines with arbitrary separators

Project description

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. https://travis-ci.org/jwodder/linesep.svg?branch=master https://coveralls.io/repos/github/jwodder/linesep/badge.svg?branch=master https://img.shields.io/pypi/pyversions/linesep.svg MIT License

GitHub | PyPI | Issues

This module provides basic functions for reading & writing text with custom line separators that can occur either before, between, or after lines — though its primary purpose is actually to allow me to experiment with proper Python packaging & testing procedures. Being actually useful is not its #1 goal.

Installation

Just use pip (You have pip, right?) to install linesep:

pip install linesep

Examples

Reading paragraphs separated by a blank line:

with open('text.txt') as fp:
    for entry in linesep.read_separated(fp, '\n\n'):
        ...

Parsing output from find -print0:

find = subprocess.Popen(
    ['find', '/', '-some', '-complicated', '-condition', '-print0'],
    stdout=subprocess.PIPE,
)
for filepath in linesep.read_terminated(find.stdout, '\0'):
    ...

A poor man’s JSON Sequence parser:

for entry in linesep.read_preceded(fp, '\x1E'):
    try:
        obj = json.loads(entry)
    except ValueError:
        pass
    else:
        yield obj

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for linesep, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size linesep-0.1.1-py2.py3-none-any.whl (7.1 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size linesep-0.1.1.tar.gz (8.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page