Handling lines with arbitrary separators
Project description
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)
Built Distribution
Close
Hashes for linesep-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ed20270cfeab99f757dc0d5190be7c0d60f5d3fda906d736d808a420fdab9d9 |
|
MD5 | bbddd50fed2528fc87af82b8349c4f93 |
|
BLAKE2b-256 | c9dc4e9627d0330995bea1220032772d116d7603b92cf183087ef24945b7dacd |