A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/elapouya/python-textops3 below:

elapouya/python-textops3: python module to manipulate text, strings and list of strings

python-textops3 provides many text operations at string level, list level or whole text level.

These operations can be chained with a 'dotted' or 'piped' notation.

Chained operations are stored into a single lazy object, they will be executed only when an input text will be provided.

To install:

pip install python-textops3

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 :

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'}]

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

Please, read documentation here :


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4