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

See Also

Prior art: <http://bugs.python.org/issue1152248#msg109117>

Project details


Download files

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

Source Distribution

linesep-0.1.1.tar.gz (8.6 kB view hashes)

Uploaded Source

Built Distribution

linesep-0.1.1-py2.py3-none-any.whl (7.1 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page