Represents a version number that can be parsed and compared.
Project description
Version Class
Represents a version number. This class cannot be extended. Sealed Class
Installation
You can install the Version Class from PyPI:
pip install verr
Constructors
Name | Description | |
---|---|---|
Version() | Initializes a new instance of the Version class. | |
Version(ver_str) | Initializes a new instance of the Version class using the specified string to be parsed | |
Version(ver_dict) | Initializes a new instance of the Version class using the specified dict to be parsed. Useful for loading json | |
Version(version) | Initializes a new instance of the Version class using the specified version. | |
Version(major, minor) | Initializes a new instance of the Version class using the specified major and minor values. | |
Version(major, minor, build) | Initializes a new instance of the Version class using the specified major, minor, and build values. | |
Version(major, minor, build, revision) | Initializes a new instance of the Version class with the specified major, minor, build, and revision numbers. |
Properties
Name | Description | |
---|---|---|
major | Gets the value of the major component of the version number for the current Version object. | |
minor | Gets the value of the minor component of the version number for the current Version object. | |
build | Initializes a new instance of the Version class using the specified major and minor values. | |
revision | Gets the value of the revision component of the version number for the current Version object. | |
major_revision | Gets the high 16 bits of the revision number. | |
minor_revision | Gets the low 16 bits of the revision number. | |
elements | Gets the number of version elements of the current instance. |
Methods
Name | Description | |
---|---|---|
parse(input) | Converts the string representation of a version number to an equivalent Version object. Raises errors if input has issues. | |
try_parse(input) | Converts the string representation of a version number to an equivalent Version object. Does not raise errors. | |
to_str() | Converts the value of the current Version object to its equivalent String representation. | |
to_str(field_count) | Converts the value of the current Version object to its equivalent String representation. A specified count indicates the number of elements to return. | |
to_tuple() | Converts the value of the current Version object to its equivalent tuple representation. | |
to_tuple(field_count) | Converts the value of the current Version object to its equivalent tuple representation. A specified count indicates the number of elements to return. |
Usage
from verr import Version
v = Version(11, 22, 33, 44)
print(v.major) # 11
print(v.minor) # 22
print(v.build) # 33
print(v.revision) # 44
print(v) # 11.22.33.44
print(v.elements) # 4
v = Version(11, 22)
print(v.major) # 11
print(v.minor) # 22
print(v.build) # 0
print(v.revision) # 0
print(v.elements) # 2
print(v.to_tuple()) # (11, 22)
print(v.to_str()) # 11.22
v = Version.parse("11.22.33")
print(v.major) # 11
print(v.minor) # 22
print(v.build) # 33
print(v.revision) # 0
print(v.elements) # 3
print(v.to_tuple()) # (11, 22, 33)
print(v.to_str()) # 11.22.33
v1 = Version.parse("1.2.2")
v2 = Version.parse("1.2.3")
print(v1 > v2) # False
print(v1 <= v2) # True
v = Version(1, 2, 3, "0xffbbff0b")
print(v.major_revision == int("ffbb", 16)) # True
print(v.minor_revision == int("ff0b", 16)) # True
print(v) # 1.2.3.4290510603
print(v.to_str(3)) # 1.2.3
print(v.to_tuple()) # (1, 2, 3, 4290510603)
print(v.to_tuple(3)) # (1, 2, 3)
print(v.elements) # 4
v_result = Version.try_parse("22.3")
if v_result[0] == True:
v = v_result[1]
print(v) # 22.3
else:
err = v_result[1]
print(e)
# JSON Usage
v1 = Version(1, 2, 3, 4)
json_str = json.dumps(v1)
print(json_str) # {"major": 1, "minor": 2, "build": 3, "revision": 4}
v2 = Version(json.loads(json_str))
print(v1 == v2) # True
v1 = Version('0xfd', 22)
json_str = json.dumps(v1)
print(json_str) # {"major": 253, "minor": 22}
v2 = Version(json.loads(json_str))
print(v1 == v2) # True
# hex usage, hex components must start with 0x and are not case sensitive
v = Version('0xd', '0x02', '0x001a', '0XAB')
print(v) # 13.2.26.171
v = Version.parse('0xd.0x02.0x001a.0XAB')
print(v) # 13.2.26.171
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
verr-1.1.1.tar.gz
(13.8 kB
view hashes)
Built Distribution
verr-1.1.1-py3-none-any.whl
(8.6 kB
view hashes)