Skip to main content

textfield_parser

Getting a string from a textfield and returns the parsed content. In general there are 3 types of saparators:

  • 'sep': the usual one, default: ','
  • 'outer_sep': if there are 2 lists this defines the list separator containing a list, default: ';'
  • 'map_sep': for separating a value pair like e.g. dictionaries, default: ':'

The expected syntax is quite easy and appropriate to the limited space of normal textfields. You can use the brackets '()' or '{}' but they are ignored.

All parsing functions enable the detection of integers and floats if the flag test_number is set True (default).

WARNING: Quotes help you to protect values with spaces but not the characters used for separating elements! This is in particular important to be aware of when using float values with 'decimals' or 'thousands'.

read_value

Reads a string and strips spaces and quotes.

def read_value(text,test_number = True)

Arguments

  • text -string- from textfield that will be parsed
  • test_number -boolean- if True (default) integers or float values are interpreted as such.

Return

  • stripped string

read_list

Reads a comma separated list and returns either the items or the remainder of the additional list when a text contains the modifier 'Not'.

def read_list(text,value_list=None,sep = ',',modifier_list_not=None,test_number = True)

Arguments

  • text -string- from textfield that will be parsed
  • value_list -list- list from which the parsed text elements will be removed when there is a modifier 'NOT'.
  • sep -char- element separator in string
  • modifier_list -list- List of modifier for excluding the listed items from value_list Default: ['!', '~', 'not', 'Not', 'NOT']
  • test_number -boolean- if True (default) integers or float values are interpreted as such.

Return

  • List of parsed parameters

Examples

**Simple list: **

  • text = "'Hello', 'a list', separated by , me "

-> ['Hello', 'a list', 'separated by', 'me']

Not list

  • text = "Not Mercedes, Renault, Citroen, Peugeaut, 'Rolls Royce'"
  • value_list = ['Mercedes', 'Audi', 'VW', 'Skoda', 'Renault', 'Citroen', 'Peugeot', 'Rolls Royce']

to

['Audi', 'VW', 'Skoda', 'Peugeot']

read_dict_of_lists

Reads a 'outer_sep'-separated list of a mapping with 'inner-sep' separated list and returns a dictionary with the map as key and a list as value.

read_dict_of_list(text,inner_sep = ',',outer_sep = ';',map_sep=':',test_number = True)

Arguments

  • text -string- from textfield that will be parsed
  • inner_sep -char- element separator of value list
  • outer_sep -char- list separator for the lists
  • map_sep -char- separates map from list
  • test_number -boolean- if True (default) integers or float values are interpreted as such.

Return

  • Dictionary of the keys and lists.

Example

"'Mercedes':expensive, German, respectable; Audi:'sportive, German, technology-advanced'; VW : 'people', 'solid', No1; Citroen:cool, Fantomas, CV2, elastic ; 'Rolls Rocye': royal,British, 'very expensive', black"

to

{'Mercedes': ['expensive', 'German', 'respectable'], 'Audi': ['sportive', 'German', 'technology-advanced'], 'VW': ['people', 'solid', 'No1'], 'Citroen': ['cool', 'Fantomas', 'CV2', 'elastic'], 'Rolls Rocye': ['royal', 'British', 'very expensive', 'black']} Map :{'Mercedes': 'expensive', 'Audi': 'sportive', 'VW': 'people', 'Citroen': 'cool', 'Rolls Rocye': 'royal'}

read_dict

Reads a comma separated list of mappings and returns a dictionary.

def read_dict(text, sep =',', map_sep=':', test_number = True)

Arguments

  • text -string- from textfield that will be parsed
  • sep -char- element separator in string
  • test_number -boolean- if True (default) integers or float values are interpreted as such.

Return

  • dictionary of parsed parameters

Example

"'Mercedes':expensive, Audi:'sportiv', VW : 'people', Citroen:cool, 'Rolls Rocye': royal"

to

{'Mercedes': 'expensive', 'Audi': 'sportiv', 'VW': 'people', 'Citroen': 'cool', 'Rolls Rocye': 'royal'}

read_dict_of_dict

Reads a dictionary of dictionaries and returns a dictory with a 2-level hierarchy

def read_dict_of_dict(text, sep=',', map_sep=':', outer_sep = ';', test_number = True)

Arguments

  • text -string- from textfield that will be parsed
  • sep -char- element separator in string
  • map_sep -char- element separator for pairs of mappings
  • outer_sep -char- list separator for the list containing a list
  • test_number -boolean- if True (default) integers or float values are interpreted as such.

Return

  • dictionary of parsed parameters

Example

"'High Class':{'Mercedes':expensive,'BWM':'sporty};'Sport Class': Porsche:'None',Ferrari:special; 'Middle Class':{VW : 'people','Renault':'fashionable',Citroen:'classy, 'Peugeot':'modern'};'Luxury Class':{'Rolls Rocye': royal, Bentley:'rare'}; 'All:{4:8.9,6:90,7:7}"

to:

{'High Class': {'Mercedes': 'expensive', 'BWM': 'sporty'}, 'Sport Class': {'Porsche': None, 'Ferrari': 'special'}, 'Middle Class': {'VW': 'people', 'Renault': 'fashionable', 'Citroen': 'classy', 'Peugeot': 'modern'}, 'Luxury Class': {'Rolls Rocye': 'royal', 'Bentley': 'rare'}, 'All': {4: 8.9, 6: 90, 7: 7}}

read_json

Reads a json formatted string and return a dictionary

Arguments

  • text -string- json-string

Return

  • dictionary of json

Example

"{"Luxury Class": {"Mercedes":"expensive","Rolls Rocye": "royal"}, "High Middle Class":{"Audi":"sportiv"}, "Middle Class" : {"Citroen":"cool","VW" : "people" }}"

to

{'Luxury Class': {'Mercedes': 'expensive', 'Rolls Rocye': 'royal'}, 'High Middle Class': {'Audi': 'sportiv'}, 'Middle Class': {'Citroen': 'cool', 'VW': 'people'}}

read_comparisons

Parses a list of comparisons and returns a list of lists with 3 items: (left, comparison-operator, right). There is an internal mapping of comparison characters: {'!=':'!','==':'=','>=':'≥','=>':'≥','<=':'≤','=<':'≤'}

def read_comparisons(text,sep = ',',formula_map = None)

Arguments

  • text -string- Textfield string
  • sep -char- element separator in string
  • modifier_map -dictionary- mapping of comparison strings to 1-char comparison. Default: {'!=': '!', '==': '=', '>=': '≥', '=>': '≥', '<=': '≤', '=<': '≤'} `

Return

  • List of 3 element lists

Examples

' anna > 1.70, norbert != 900, cindy <= 1.65'

to

[['anna', '>', 1.7], ['norbert', '!', 900.0], ['cindy', '≤', 1.65]]

Release files for textfield-parser 0.0.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for textfield-parser 0.0.18
File Size Uploaded
textfield_parser-0.0.18.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for textfield-parser 0.0.18
File Interpreter ABI Platform
textfield_parser-0.0.18-py3-none-any.whl Python 3 none any Details

Total release size: 13.4 kB

Release files / textfield_parser-0.0.18.tar.gz

Download URL textfield_parser-0.0.18.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
13d7d45851b40fbf2f10c882ef83ade80d44ee53128a6d7e6a063fdbf1918c76
BLAKE2b-256 checksum
How to use checksums
0ce0e05afa1e1f6b0dbfd77a2cbf4ab69063b54aae372638b070363fd99b66d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

Release files / textfield_parser-0.0.18-py3-none-any.whl

Download URL textfield_parser-0.0.18-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f3fbac49a163004c4b9be57b8385b72241608e87496e6ae9161121f9b831fb9e
BLAKE2b-256 checksum
How to use checksums
574dceb158b7cc6a20e4cf9cf0347a69b99332b87dc4f894fa048e51f10934cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.3

Release history Release notifications | RSS feed

0.0.29

2 release files

0.0.28

2 release files

0.0.27

2 release files

0.0.26

2 release files

0.0.25

2 release files

0.0.24

2 release files

0.0.23

2 release files

0.0.22

2 release files

0.0.21

2 release files

0.0.20

2 release files

0.0.19

2 release files

This release

0.0.18 This release

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page