Skip to main content

Makes the ConfigParser smarter.

Project description

Makes the ConfigParser smarter.

A SmartParser provides methods to parse options as objects of the datetime-modules, as list or as ‘smartlist’. Items of a smartlist are automatically tried to converted into different types (such as: int, float, time, date, datetime).

It also provides additional get- and itme-methods (xget, xitem): xget tries to get the option as one of the following types (in this order): int, float, boolean, time, date, datetime, smartlist. If every type fails the option is given as string.

Latest Version

The latest version of this project can be found at : http://github.com/thomst/smartparse.

Installation

  • Option 1 : Install via pip

    pip install smartparse
  • Option 2 : If you have downloaded the source

    python setup.py install

Documentation

How to use?

import io
from smartparse import SmartParser

CONFIG = """
[Section]
bool = yes
int = 3
float = 3.3
time = 23:55:00
date = 2013.04.24
datetime = 2013.04.24 23:55:00
list = one two three four
smartlist = 3 4.4 1:55 yes 2013.04.24 2013.04.24_01:55
"""

config = SmartParser(allow_no_value=True)
config.readfp(io.BytesIO(CONFIG))
section = dict(self.config.xitems('Section'))

section['bool']             # True
section['datetime']         # datetime.datetime(2013, 4, 24, 23, 55)
section['list']             # ['one', 'two', 'three', 'four']
section['smartlist'][2]     # datetime.time(1, 55)
section['smartlist'][4]     # datetime.date(2013, 4, 24)

Changes v0.5:

Backwards incompatibility:

getsmartlist became getxlist. Removed the config-methods. Use the timeparser-module directly to change the configuration about parsing time-, date- and datetime-objects.

Reporting Bugs

Please report bugs at github issue tracker: https://github.com/thomst/smartparse/issues

Author

thomst <thomaslfuss@gmx.de> Thomas Leichtfuß

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

smartparse-0.3.1.tar.gz (3.2 kB view details)

Uploaded Source

File details

Details for the file smartparse-0.3.1.tar.gz.

File metadata

  • Download URL: smartparse-0.3.1.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for smartparse-0.3.1.tar.gz
Algorithm Hash digest
SHA256 f62cbffc5e4696440fbc1272241bdbb4d70cb65f582bd49c8d840e7f895537c6
MD5 8e2707f4b7fc19e6b136302bad8a922a
BLAKE2b-256 265920db3c4cfe8226ccba4f91e786f778fcffdbb3c6f6506f14f0ee450de9ef

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