Answer the question
In order to leave comments, you need to log in
How to compare versions using python?
Hello. Something I'm already sleepy and can't figure out how to compare strings with program versions. For example, there are lines
s = "1.2.1"
ss = "2.1.2"
How to find out which version is older?
Answer the question
In order to leave comments, you need to log in
stackoverflow.com/questions/11887762/how-to-compar...
stackoverflow.com/questions/1714027/version-number...
>>> from distutils.version import LooseVersion, StrictVersion
>>> LooseVersion("2.3.1") < LooseVersion("10.1.2")
True
>>> StrictVersion("2.3.1") < StrictVersion("10.1.2")
True
>>> StrictVersion("1.3.a4")
Traceback (most recent call last):
...
ValueError: invalid version number '1.3.a4'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question