Utils for simplifying work with classes
Project description
Utils for simplifying work with classes
Usage:
pip install class-utils
Properties:
Mixins:
default_property
from class_utils import default_property
class Point():
x = default_property('x')
y = default_property('y')
def __init__(self, x, y):
self.x = x
self.y = y
point1.x = 3
print(point1.x) # => 3
typed_property
from class_utils import typed_property
class Person():
name = typed_property('name', str)
def __init__(self, name):
self.name = name
person1 = Person('Bill')
print(person1.name) # => 'Bill'
person1.name = 123 # => TypeError: name must be a <class 'str'>
DefaultRepresentationMixin
from class_utils import default_property, DefaultRepresentationMixin
class Date(DefaultRepresentationMixin):
day = default_property('day')
month = default_property('month')
year = default_property('year')
def __init__(self, day, month, year):
self.day = day
self.month = month
self.year = year
date1 = Date(12, 12, 2012)
print(date1) # => Date({'_day': 12, '_month': 12, '_year': 2012})
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
class-utils-0.0.4.tar.gz
(2.0 kB
view hashes)
Built Distribution
Close
Hashes for class_utils-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 36e6381ed4243c7dac192015d81eef6301f58c2fe908bb116c39e7f28429a87e |
|
MD5 | 47f782ca98da48b01f5abeab62052229 |
|
BLAKE2b-256 | 271a3021d0781933d4f6f1b1c55b8510e22ef3f1c1b383c3ca822d266cc10c30 |