Skip to main content

Python string unformatter.

Project description

unformat

Python string unformatter.

Simple string pattern matching using f-string-like syntax. This module cannot do anything more than re but is much easier to use.

Installation

pip install -U unformat

Usage

Unformatting returns a list-like object.

from unformat import compile, unformat

unformat("{name}_{idx}.csv", "data_001.csv")  # Values(name='data', idx='001')
unformat("{name}_{idx:int}.csv", "data_001.csv")  # Values(name='data', idx=1)
unformat("{name}_{idx}.csv", "data001.csv")  # Error!
name, idx = unformat("{name}_{idx}.csv", "data_001.csv")  # `Values` is list-like

# object oriented
ptn = compile("{name}_{idx}.csv")
ptn.unformat("data_001.csv")  # Values(name='data', idx='001')

Model-based unformatting is also supported.

from unformat import UnformatModel

class Version(UnformatModel):
    pattern = "{major}.{minor}.{micro}"  # not a field
    major: int
    minor: int
    micro: int

version = Version.from_string("0.2.1")  # Version(major=0, minor=2, micro=1)

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

unformat-0.1.1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

unformat-0.1.1-cp311-none-win_amd64.whl (155.3 kB view details)

Uploaded CPython 3.11 Windows x86-64

File details

Details for the file unformat-0.1.1.tar.gz.

File metadata

  • Download URL: unformat-0.1.1.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.14.16

File hashes

Hashes for unformat-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fb4cc50952682a69c3ef4adcdc904d6ad631dddcf86caf5bd76c72665bbe6b9a
MD5 e6080406c9ecb8ae5fa3caee5684ac5a
BLAKE2b-256 918808ff2d0684cf91c9b27300a7f382ff52ed4de80d3b4bc1605597054f43ce

See more details on using hashes here.

File details

Details for the file unformat-0.1.1-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for unformat-0.1.1-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 51e3e86034e92d43b3374a8b401c6ce513c5b7e254e3ce379aeb5e3beff7e064
MD5 42dfbcc48dfd4e4e90370b7dd0b02cb9
BLAKE2b-256 761f1d80e8b0d87da4bc41123ecdc3c4aed0086d4a253a6d3052982cb1608eec

See more details on using hashes here.

Supported by

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