Python text operations module
Project description
Install
To install:
pip install python-textops3
Overview
The usual way to use textops is something like below. IMPORTANT : Note that textops library redefines the python bitwise OR operator ‘|’ in order to use it as a ‘pipe’ like in a Unix shell:
from textops import * result = "an input text" | my().chained().operations() or for result_item in "an input text" | my().chained().operations(): do_something(result_item) or myops = my().chained().operations() # and later in the code, use them : result = myops("an input text") or result = "an input text" | myops
An “input text” can be :
a simple string,
a multi-line string (one string having newlines),
a list of strings,
a strings generator,
a list of lists (useful when you cut lines into columns),
a list of dicts (useful when you parse a line).
So one can do:
>>> 'line1line2line3' | grep('2').tolist() ['line1line2line3'] >>> 'line1\nline2\nline3' | grep('2').tolist() ['line2'] >>> ['line1','line2','line3'] | grep('2').tolist() ['line2'] >>> [['line','1'],['line','2'],['line','3']] | grep('2').tolist() [['line', '2']] >>> [{'line':1},{'line':'2'},{'line':3}] | grep('2').tolist() [{'line': '2'}]
Examples
Piped then dotted notation (recommended):
>>> print('this is an error\nthis is a warning' | grepi('error').first().upper()) THIS IS AN ERROR
You could use the pipe everywhere (internally a little less optimized, but looks like shell):
>>> print('this is an error\nthis is a warning' | grepi('error') | first() | strop.upper()) THIS IS AN ERROR
To execute an operation directly from strings, lists or dicts with the dotted notation, you must use textops Extended types : StrExt, ListExt or DictExt:
>>> s = StrExt('this is an error\nthis is a warning') >>> print(s.grepi('error').first().upper()) THIS IS AN ERROR
Documentation
Please, read documentation here :
News
3.1.0 (2020-06-25)
add TupleExt
DictExt now support pickle
3.0.8 (2019-10-08)
add encoding & encoding_errors arguments to cat()
3.0.7 (2019-10-01)
add separators argument to parse_smart()
3.0.6 (2019-09-25)
add key_filter argument to parse_smart()
3.0.5 (2019-06-14)
add decode_bytes()
3.0.3 (2018-11-07)
Migrate from python 2 to python 3
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for python_textops3-3.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b35570e936180bbddd40a749cd46a6512f0352463113a1b3dcce7ca011678f6e |
|
MD5 | 0da71a837fa6d8ce1e81a13cb8a45b83 |
|
BLAKE2b-256 | 2b6954875ea4f9177344a8ec5eb0e47210dce6b94bfc551c658c4006e6627c4b |