I need a Python analog for Version
from C#
. I can't find built-in class for it. Of course, it is better to use built-in, but I can't find 3'rd party library too. Does it exist?
For example, I want to convert line like '4.3.8' to some object to compare with another one.
Asked
Active
Viewed 143 times
0
-
As I know you can get your Python version using the module `sys`: `sys.version` – Víctor M Feb 24 '16 at 10:02
1 Answers
2
>>> sys.version
'2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)]'
>>> sys.version_info
sys.version_info(major=2, minor=7, micro=11, releaselevel='final', serial=0)
>>> sys.winver # Windows
'2.7-32'
>>> os.uname() # Unix
>>> win32api.GetVersion() # Windows
>>> win32api.GetVersionEx() # Windows
>>> sys.version_info >= (2, 6)
True
>>> map(int, '4.3.8'.split('.')) >= [4, 2]
True
>>> map(int, '4.3.8'.split('.')) >= [4, 4]
False
>>> from distutils.version import StrictVersion
>>> StrictVersion("4.3.8") < StrictVersion("4.4")
True
Update: conversion examples added as you extended / modified your question

kxr
- 4,841
- 1
- 49
- 32