Skip to main content

Convert a string representation of an int, float, None, True, False, or JSON to its native type. For None, True, and False, case is irrelevant.

Project description

Convert the string representation of a Python type to its native type.

https://travis-ci.org/geowurster/str2type.svg?branch=master https://coveralls.io/repos/geowurster/str2type/badge.svg?branch=master

Convert a string representation of an int, float, None, True, False`, or JSON to its native type. For None, True, and False, case is irrelevant. The primary use-case of this function is automatically parsing user-input from the commandline into Python types. Argument parsers usually handle this no problem but if a flag can take multiple types then ``str2type() can serve as the decoder.

>>> from str2type import str2type
>>> print(str2type("1.23"))
1.23
>>> print(str2type("1.")
1.0
>>> print(str2type(".2"))
0.2
>>> print(str2type("NonE"))
None
>>> print(str2type("String"))
"String"

Installing

Via pip:

$ pip install str2type

From master branch:

$ git clone https://github.com/geowurster/str2type $ cd str2type $ pip install .

Developing

Install:

$ pip install virtualenv $ git clone https://github.com/geowurster/str2type $ cd str2type $ virtualenv venv $ source venv/bin/activate $ pip install -r requirements-dev.txt -e . $ nosetests –with-coverage $ pep8 –max-line-length=95 str2type

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

str2type-0.4.0.tar.gz (5.7 kB view details)

Uploaded Source

File details

Details for the file str2type-0.4.0.tar.gz.

File metadata

  • Download URL: str2type-0.4.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for str2type-0.4.0.tar.gz
Algorithm Hash digest
SHA256 efa6018dc9e305ee63a4be2cc37fc0b39fbd1b28a2fbc02d0d82c8cc2cf0f919
MD5 84b468a3d4bdcc0965407cc066b8a52a
BLAKE2b-256 e3ec1c8ed31219a81da884565575f949c971f0c4beea161b6459c7e3692b2da6

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