比较python系统版本的便利函数

versionutil的Python项目详细描述


比较python系统版本的便利函数

安装

从项目根目录:

$ python setup.py install

用法

提供比较python版本,以便您可以检查主版本、次版本和微版本:

from versionutil import compare_python, PYTHON

# compare_python will return a boolean value against the current system version.
# PYTHON represents an instance of an object that is the current system version.

# It will check at the most significant value you signify. Default is equality check.
# True using 2.7.9:
PYTHON == '2'
PYTHON == '2.7'
PYTHON == '2.7.9'
compare_python('2')
compare_python('2.7')
compare_python('2.7.9')

# True using 3.4.4:
PYTHON == '3'
PYTHON == '3.4'
PYTHON == '3.4.4'
compare_python('3')
compare_python('3.4')
compare_python('3.4.4')

# False in 3.4.4:
PYTHON != '3.5'
PYTHON != '3.4.5'
compare_python('3.5')
compare_python('3.4.5')

# Works with ints and even floats:
PYTHON == 2.7
compare_python(2.7)

# Different comparisons exist, default comp='=='
PYTHON != 3
PYTHON < 3
PYTHON < 3.0
PYTHON > 2.6
PYTHON >= 2.7
PYTHON < 3.1
compare_python(3, '!=')
compare_python(3, '<')
compare_python(3.0, '<')
compare_python(2.6, '>')
compare_python(2.7, '>=')
compare_python(3.1, comp='<')

# To test against a custom system version (ignore sys.version_info):
compare_python(5.4, sysv=(5, 4, 5))
# or to create a PYTHON like object for 5.4.5:
from versionutil import PythonVersion
pv545 = PythonVersion(sysv=(5, 4, 5))
if pv545 == 5.4: # True...

# Useful for handling imports, where otherwise pyfuture and pasteurize might not have what you need.
if PYTHON < 3:
    from oldapi import OldAPI as API
elif PYTHON == 3.0 or PYTHON == 3.1:
    from newapi import OtherAPI as API
elif PYTHON >= 3.2:
    from newapi import NewAPI as API

发行说明

0.1.2:Check is_instance(str) for 3.4 and basestring for <
0.1.1:Added PYTHON global and PythonVersion class for easier usage (PYTHON < 2.7)
0.1.0:Alpha finished, tested fully with tox
0.0.1:Project created

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

推荐PyPI第三方库


热门话题
orm如何在Java中实现规范化映射?   java以编程方式修改Xtext生成的Mwe2工作流   java正在覆盖外部文件中的现有数据,如何停止?   java在ANTLR BNF语法符号中epsilon的等价物是什么?   java如何使用Hibernate@Anyrelated注释?   代码生成生成java类并在运行时加载它   java Maven无法在本地jar文件中收集依赖项   java NetBeans IDE 8.2不显示错误消息   java Selenium web驱动程序找不到元素   java如何修复“拒绝访问属性”invoke“”的权限?   JavaApacheJClouds,从比日期更早的blob中删除blob的最佳方法   java如何比较和排序树集中的项目?   使用JavaSpring和无头/解耦CMS   java使用swagercodegen在不同的类中生成端点   Java外部Keylistener没有响应