libb.attrs

attrs(*attrnames)[source]

Create property getters/setters for private attributes.

Automatically generates property accessors for attributes that follow the _name convention, allowing clean access to private attributes.

Parameters:

attrnames (str) – Names of attributes to create properties for (without underscore prefix).

Return type:

None

Basic Usage:

>>> class Foo:
...     _a = 1
...     _b = 2
...     _c = 3
...     _z = (_a, _b, _c)
...     attrs('a', 'b', 'c', 'z')
>>> f = Foo()
>>> f.a
1
>>> f.a+f.b==f.c
True

Setter Functionality:

>>> f.a = 2
>>> f.a==f._a==2
True

Lazy Definitions:

>>> len(f.z)==3
True
>>> sum(f.z)==6
True
>>> f.z[0]==f._z[0]==1
True
>>> f.z = (4, 5, 6,)
>>> sum(f.z)
15
>>> f.a==2
True