Skip to main content

Handling lines with arbitrary separators

Project description

Project Status: Active — The project has reached a stable, usable state and is being actively developed. CI Status coverage pyversions MIT License

GitHub | PyPI | Documentation | Issues | Changelog

linesep provides basic functions & classes for reading, writing, splitting, & joining text with custom separators that can occur either before, between, or after the segments they separate.

Installation

linesep requires Python 3.8 or higher. Just use pip for Python 3 (You have pip, right?) to install:

python3 -m pip install linesep

Examples

Reading sections separated by a “---” 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 Text Sequence parser:

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

Read from a text file one paragraph at a time:

with open("my-novel.txt") as fp:
    for paragraph in linesep.read_paragraphs(fp):
        ...

Split input from an anyio.TextReceiveStream on newlines:

async with anyio.TextReceiveStream( ... ) as stream:
    splitter = linesep.UnicodeNewlineSplitter()
    async for line in splitter.aitersplit(stream):
        print(line)

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.5.1.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

linesep-0.5.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file linesep-0.5.1.tar.gz.

File metadata

  • Download URL: linesep-0.5.1.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for linesep-0.5.1.tar.gz
Algorithm Hash digest
SHA256 e4c79a943f7aa5d0b300c5e9a95e9d262cec6e5b3ee87a25aea629fae31f7565
MD5 d51333296b70d88a187a42686aa397cf
BLAKE2b-256 9695b019efc242341fbcf7286c59d25db86647a15cfb5b9475c486ea86b6eb3e

See more details on using hashes here.

File details

Details for the file linesep-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: linesep-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for linesep-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 278993c478617b56d61b398657ca74242be0ae9e927a1925556f68cc627801ce
MD5 fad9a628a23dc3584324a56ac555d6a3
BLAKE2b-256 26049b706c27651d98cbc1db090f542f4abd6de4288a917cad15790b90d9b71c

See more details on using hashes here.

Supported by

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