Skip to content

Instantly share code, notes, and snippets.

@gregneagle
Last active January 7, 2018 19:45
Show Gist options
  • Save gregneagle/2c5b535c723aea5d3fc7 to your computer and use it in GitHub Desktop.
Save gregneagle/2c5b535c723aea5d3fc7 to your computer and use it in GitHub Desktop.
Proper software version comparisons in Python
% python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> os_vers_1 = "10.9.5"
>>> os_vers_2 = "10.10"
>>> os_vers_2 > os_vers_1
False
>>> from distutils import version
>>> version.LooseVersion(os_vers_2) > version.LooseVersion(os_vers_1)
True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment