1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
.. _sec.properties.parts:
Accessing Parts of a Version Through Names
==========================================
The :class:`~semver.version.Version` class contains attributes to access the different
parts of a version:
.. code-block:: python
>>> 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 :py:exc:`python: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 :ref:`sec.replace.parts`.
In case you need the different parts of a version stepwise, iterate over the :class:`~semver.version.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']
|