3.7. Accessing Parts of a Version Through NamesΒΆ
The Version
class contains attributes to access the different
parts of a version:
>>> v = Version.parse("3.4.5-pre.2+build.4")
>>> v.major
3
>>> v.minor
4
>>> v.patch
5
>>> v.prerelease
'pre.2'
>>> v.build
'build.4'
However, the attributes are read-only. You cannot change any of the above attributes.
If you do, you get an AttributeError
:
>>> v.minor = 5
Traceback (most recent call last):
...
AttributeError: attribute 'minor' is readonly
If you need to replace different parts of a version, refer to section Replacing Parts of a Version.
In case you need the different parts of a version stepwise, iterate over the Version
instance:
>>> for item in Version.parse("3.4.5-pre.2+build.4"):
... print(item)
3
4
5
pre.2
build.4
>>> list(Version.parse("3.4.5-pre.2+build.4"))
[3, 4, 5, 'pre.2', 'build.4']