File: convert-version-into-different-types.rst

package info (click to toggle)
python-semver 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 700 kB
  • sloc: python: 1,972; makefile: 28
file content (26 lines) | stat: -rw-r--r-- 860 bytes parent folder | download
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
.. _sec.convert.versions:

Converting a Version instance into Different Types
==================================================

Sometimes it is needed to convert a :class:`~semver.version.Version` instance into
a different type. For example, for displaying or to access all parts.

It is possible to convert a :class:`~semver.version.Version` instance:

* Into a string with the builtin function :func:`str`::

    >>> str(Version.parse("3.4.5-pre.2+build.4"))
    '3.4.5-pre.2+build.4'

* Into a dictionary with :meth:`~semver.version.Version.to_dict`::

    >>> v = Version(major=3, minor=4, patch=5)
    >>> v.to_dict()
    {'major': 3, 'minor': 4, 'patch': 5, 'prerelease': None, 'build': None}

* Into a tuple with :meth:`~semver.version.Version.to_tuple`::

    >>> v = Version(major=5, minor=4, patch=2)
    >>> v.to_tuple()
    (5, 4, 2, None, None)