Skip to main content

classattr provides tools to manage class and object attributes

Project description

from classattr import ClassAttr, RAISE, FORCE

class Point(ClassAttr):

## class atribute, can be default value x = 0 y = 0 color = ‘red’

def __init__(self,attr = {},mode=RAISE,**kwargs):

ClassAttr.__init__(self,attr,mode,**kwargs)

class Dot(Point):

## class atribute, can be default value radius = 1

def __init__(self,attr = {},mode=RAISE,**kwargs):

ClassAttr.__init__(self,attr,mode,**kwargs)

p = Point(y=3) print(‘x = {}, y = {}’.format(p.x,p.y))

p.set(x=6) p.set({‘y’:8}) print(‘x = {}, y = {}’.format(p.x,p.y))

p.set(z=4,mode=FORCE) print(p.get_keys()) print(p.get())

d = Dot(x=12,y=24,radius=3) print(‘x = {}, y = {}, r = {}’.format(d.x,d.y,d.radius))

d.set(radius=1.5) d.color = ‘blue’ print(d.get())

d.set(unknown_var = 53) # raise an error, if you want to create use mode=FORCE

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

classattr-1.0.1.tar.gz (2.1 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page