跳转到主要内容

将整数、浮点数、None、True、False或JSON的字符串表示转换为它们的原生类型。对于None、True和False,大小写无关。

项目描述

将Python类型的字符串表示转换为原生类型。

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

为什么?

当构建命令行实用程序时,--arg key=val 语法很有用,尤其是当keyval 将作为内部使用的Class(key=val)。此模块专门用于与CLI框架click一起使用,所包含的扩展也表现良好,但也可以在其他地方使用str2type.str2type()函数。

示例

有关click集成示例,请参阅examples目录。其他内容主要由一个函数处理。

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

支持类型

仅支持标准内置Python类型以及JSON字符串

  • int

  • float

  • None

  • True

  • False

  • JSON

安装

通过pip

$ pip install str2type

从master分支

$ git clone https://github.com/geowurster/str2type
$ cd str2type
$ pip 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

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

str2type-0.4.1.tar.gz (7.2 kB 查看哈希)

上传时间:

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面