Skip to main content

Parsing Textfields

Project description

textfield_parser

Getting a string from a textfield and returns the parsed content.

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 = None)`

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

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

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

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

def read_value_lists(text,value_list=None,inner_sep = ',',outer_sep = ';',map_sep=':')`

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

Return

  • Dictionary of the keys and lists.

Example

text = "'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" -> {'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_map

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

def read_map(text, sep=',')

Arguments

  • text -string- from textfield that will be parsed
  • sep -char- element separator in string

Return

  • dictionary of parsed parameters

Example

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

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

read_json

Reads a json formatted string and return a dictionary

Arguments

  • text -string- json-string

Return

  • dictionary of json

Example

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

-> `{'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'

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

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

textfield_parser-0.0.11.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

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

textfield_parser-0.0.11-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file textfield_parser-0.0.11.tar.gz.

File metadata

  • Download URL: textfield_parser-0.0.11.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for textfield_parser-0.0.11.tar.gz
Algorithm Hash digest
SHA256 b128a0b1dc1c7f188b16809bfa6e225b029574b47394884f38316447f8ec78c8
MD5 84f3a179bddcd1eaf6e2d8ddee82a0a9
BLAKE2b-256 44f656c9a9629560921888ea4c5efefcae532a82e7ec88711e4c8db1db8bc774

See more details on using hashes here.

File details

Details for the file textfield_parser-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: textfield_parser-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for textfield_parser-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 7573091f0e73ade0ac8f2f3cad77468666d00c8ba2198f582576c14618d88d12
MD5 12a0afdffc25e65de9e260385a3d34fd
BLAKE2b-256 cf564db3e729508811116f07537febb380217f7d5715ea1039b286c412caa7da

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