这是一个软件库,它接受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
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
推荐PyPI第三方库