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.0.tar.gz
(7.3 kB
view hashes)
Built Distribution
Close
Hashes for linesep-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59b36a6050d78c095a71da376d1363a01a8a13ddf2ce9a44d9f5b6e5a3e7bc31 |
|
MD5 | 93ef66706fffa6f2f9917cc5fcf9b2ac |
|
BLAKE2b-256 | 5f547e746b3afde3b336a31acd4f97883508f23759a4b1ef44df9019234a2153 |