ver_cmp('1.6.2', '1.6')
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | def ver_cmp(v1, v2):
lst = map(lambda x, y: ((0 if not x else x), (0 if not y else y)),
v1.split('.'), v2.split('.'))
for num1, num2 in lst:
if num1 != num2:
if num1 > num2:
return (1, 'greater')
else:
return (2, 'less')
return (0, 'equal')
# Example:
#
# >>> print ver_cmp('1.6.2', '1.6')
# >>> (1, 'greater')
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Why not use distutils module?
#
Please login first before commenting.