linesep 0.5.0

Creator: bradpython12

Last updated:

Add to Cart

Description:

linesep 0.5.0

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.7 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)

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.