Skip to main content

Python text operations module

Project description

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.

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.0.5 (2019-06-14)

  • add decode_bytes()

3.0.3 (2018-11-07)

  • Migrate from python 2 to python 3

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

python-textops3-3.0.5.tar.gz (77.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_textops3-3.0.5-py3-none-any.whl (61.4 kB view details)

Uploaded Python 3

File details

Details for the file python-textops3-3.0.5.tar.gz.

File metadata

  • Download URL: python-textops3-3.0.5.tar.gz
  • Upload date:
  • Size: 77.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.6

File hashes

Hashes for python-textops3-3.0.5.tar.gz
Algorithm Hash digest
SHA256 5e2c574d3f301b741cae505d7c085572d75a014d89d92ba388eeecb4ef9a14f6
MD5 b25f077dd479f8e31286c3c593cebf7f
BLAKE2b-256 47d979482544f59284b03d9b4709d5787692a42264f409ae8762a16f2cc389c3

See more details on using hashes here.

File details

Details for the file python_textops3-3.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for python_textops3-3.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e2bfc97fac3e8f089e6a619e31be21a839306454e3e226a1d77e4bc16c7c1d95
MD5 7b7b65fdcc2fd3fb2e0cb63ced603b01
BLAKE2b-256 8aa44eb2e9a2b2c468126dec7ee55132be97f38bbf2c7437082bd33c03c86a80

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page