接受2版本字符串作为输入,并返回其中一个是否大于、等于或小于另一个

compare-string-version的Python项目详细描述


这是一个软件库,它接受2个版本字符串作为输入,并且 返回一个是否大于、等于或小于另一个。 例如:“1.2”大于“1.1”。

要求:python 3。及以上

用法:

from compare_string_version import compareVersion
print(compareVersion(a,b))

预期收益

a==b:

    a is equal to b

a>b:

    a is greater than b

a<b: 

    a is less than b

例外情况:

a为空和/或b为空: 值不能为空:两个值都必须为字符串
a和/或b不是字符串: 两者都必须是字符串

假设:

a and b are string

a and b are not null (None)

both version strings only contain numbers (0...9) and this char '.':

    123.456.789.012

    'A..Z','a..z' and any other chars like "! @ # $ % * [ } ] { ^ ç ? ; : . > , < | " will be removed from the comparison:
        some adjustment would be applied after char removal:
        '..' will be replaced by '.'
        string ending in '.' will be shorted by 1

this '..' will not be accepted as it is '.' duplicated:
        '10..12..13..14' will become '10.12.13.14'

the comparison would be from the group split by the char '.':
        10.12.13.14 would be treated as 10 12 13 14
        01.10.100.001 would be treated as 1 10 100 1

all the comparison would check the integer part of the version:
        '10.0' is equal to '010.0.0.0.0.0.0.0' because int('10.0') is equal to int ('010')

whoever version number has the higher far left group would be named as greater:
        10.0.0.0.0.1 is greater then 9.9.9.9.9.9.9
        0.1.0.0.0.0.1 is greater than 0.0.9
        the same "int" rule will be applied for any other group in the string

all '0's from the left will be disregarded if its value is '0':
        1.0.0.0 is equal to 1.0 and it is equal to 1

使用以下.py来测试数据

test997.py已生成output5.txt

test996.py已生成output4.txt

test995.py生成了output1.txt和output2.txt

test994.py已生成output3.txt

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

推荐PyPI第三方库


热门话题
java我能在这个程序中更好地使用内存吗?   为什么我的Java while循环迭代了一半   java IntelliJ IDEA不在构建时复制资源   socket仅在Java TCP服务器输出上检查客户端断开连接   java游戏物理摩擦   java片段onClick调用方法   symja数学分析器中无法识别java Abs[x]   java在使用泛型时创建二进制搜索树类的实例?   java在外键约束表上的添加和删除   语法java表达式的含义,如果有条件   java创建内联对象并作为参数传递   是否有相当于Redis排序集(zset)的Java数据结构   java找不到适合的方法(无参数)   音频文件操作给定字节帧的音量Java   Eclipse4不以JavaWebStart启动   java如何使用org在JSON对象中获取嵌套的键元素。json?   java与Jackson的反序列化:“org.codehaus.Jackson.map.JsonMappingException:无法反序列化[projectname]的实例。”   字符串的Java正则表达式   spring集成上的java检测缺火指令