接受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 toString()方法打印空值   java大型IN子句   如何使用JavaSpring在JavaScriptjQuery中设置post路径   java ByteArrayOutputStream已上载到服务器   java为什么轮询在SocketIO上获取数据“无法加载请求的项”?   java源代码应该以UTF8格式保存   Java数据库轮询器?   在Java中将double转换为float   java AccessDeniedException:C:\Windows\System32\drivers\etc\hosts