运行时用于变量类型检查器/验证器/转换器的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中的js?   java未来超时和IO超时   java apache camel多播以异步方式执行聚合   java需要710次尝试在Android和Raspberry Pi之间建立socket连接   在Java中使用“+,”循环绘制形状   java安卓:如何计算两点之间的距离   java多线程Hello World   刷新后缓存共享变量的java Freemarker模板   java我试图通过迭代用整数填充数组,但我得到了ArrayIndexOutOfBoundsException   JNI C++到java 32位图像的不正确显示   java哪个更快:克隆还是使用流?   java cache2k和Generic T不能很好地结合在一起   java如何在读取文件之前更新文件内容?   java如何在GWT中从JSNI方法调用JSNI方法   将MySQL类型文本映射到Java Hibernate的类型   java如何按长度对字符串排序   java RecyclerView:在滚动期间不断更改数据