Parse strings using a specification based on the Python format() syntax.
Anonymous (fixed-position), named and typed values are supported. Also the alignment operators will cause whitespace (or another alignment character) to be stripped from the value.
You may not use both fixed and named values in your format string.
The types supported in “:type” expressions are the regular expression character group types d, D, w, W, s, S and not the string format types.
So, for example, some fixed-position parsing:
>>> r = parse('hello {}', 'hello world') >>> r.fixed ('world', )>>> r = parse('hello {:d} {:w}', 'hello 12 people') >>> r.fixed ('12', 'people')
And some named parsing:
>>> r = parse('{greeting} {name}', 'hello world') >>> r.named {'greeting': 'hello', 'name': 'world'}>>> r = parse('hello {^} world', 'hello there world') >>> r.fixed ('there', )
A ValueError will be raised if there is no match:
>>> r = parse('hello {name:w}', 'hello 12')
ValueError: ...
See also the unit tests at the end of the module for some more examples.
This code is copyright 2011 eKit.com Inc (http://www.ekit.com/) See the end of the source file for the license of use.
Metadata
Release files for parse 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| parse-1.0.0.tar.gz | 3.8 kB | Without provenance | Details for parse-1.0.0.tar.gz |
Release files / parse-1.0.0.tar.gz
| Download URL | parse-1.0.0.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
545fd0e4862011896316f3c36ab6b672733ecc4a06ac3d84b6e16a1f4caac9a7
|
|
BLAKE2b-256 checksum How to use checksums |
87a5286d63ead2f448cb677ba6927cb3d2927e94930440d6333b634ea8b7f645
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for parse 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.