运行时用于变量类型检查器/验证器/转换器的python库。

pytypeutil的Python项目详细描述


pytypeutil

https://badge.fury.io/py/pytypeutil.svghttps://img.shields.io/pypi/pyversions/pytypeutil.svghttps://img.shields.io/travis/thombashi/pytypeutil/master.svg?label=Linuxhttps://img.shields.io/appveyor/ci/thombashi/pytypeutil/master.svg?label=Windowshttps://coveralls.io/repos/github/thombashi/pytypeutil/badge.svg?branch=masterhttps://img.shields.io/github/stars/thombashi/pytypeutil.svg?style=social&label=Star

小结

运行时用于变量类型检查器/验证器/转换器的python库。

用法

类型检查

>>> frompytypeutil.typeimportInteger>>> Integer(1).is_type()True
>>> Integer(1.1).is_type()False

类型验证

>>> frompytypeutil.typeimportInteger>>> Integer(1).validate()>>> try:... Integer(1.1).validate()... exceptTypeErrorase:... print(e)...invalid value type: expected=INTEGER, actual=<type 'float'>

类型转换

转换

>>> frompytypeutil.typeimportInteger>>> frompytypeutilimportTypeConversionError>>> Integer("1").convert()1
>>> try:... Integer(1.1).convert()... exceptTypeConversionErrorase:... print(e)...failed to convert from float to INTEGER

尝试转换

>>> frompytypeutil.typeimportInteger>>> Integer("1").try_convert()1
>>> print(Integer(1.1).try_convert())None

强制转换

>>> frompytypeutil.typeimportInteger>>> Integer("1").force_convert()1
>>> Integer(1.1).force_convert()1

功能

支持的类型如下:

  • 布尔
  • 日期时间
  • dict
  • 内景
  • 浮动
    • 实数
    • 无限
    • 不是数字
  • str
    • 空字符串

类型检查/验证/转换结果将根据^{tt1}决定$ 可以传递给构造函数。API引用可以在文档中找到。

安装

pip install pytypeutil

依赖关系

python 2.7+或3.3+

测试依赖性

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Eclipse内存分析器(MAT):不显示当前正在运行的进程   java Apache Velocity:转义字符不能作为关联数组键用于PHP   不截断零的java格式十进制输出   在另一个类文件中调用时返回空值的java getter   java集合获取连接   java解析json使用Gson登录系统应用程序强制关闭   java DelferredResult带有两个请求的ajax请求   java可降低功耗,同时应使用无线   java BoxLayout无法共享错误?   java如何使用计时器制作闹钟   java使用OAuth2保护RESTWeb服务:一般原则   java在一个jframe上显示多个图像和按钮