Skip to content

Dynamic object class which allows dynamic adding of attributes and dict-like access to the attributes.

License

Notifications You must be signed in to change notification settings

vladimir-kraus/dynobject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dynobject

Dynamic object class which allows dynamic adding of attributes on the run and dict-like access to the attributes.

>>> a = DynObject()
>>> a.x = 10  # dynamic adding of attributes
>>> a.x  # access to attributes
10
>>> a["x"]  # access to attributes like to a dict
10

DynObject can be initialized from dict or using keyword arguments.

>>> d = dict(x=10, y=20)  # or d = {"x": 10, "y": 20}
>>> a = DynObject(d)
>>> b = DynObject(x=10, y=20)  # equivalent to the above

Convert to or use as dict:

>>> a = DynObject(x=10, y=20)
>>> d1 = a.__dict__  # not a copy!
>>> d2 = dict(a.__dict__)  # a copy
>>> d3 = {k: a[k] for k in dir(a)}  # a copy

About

Dynamic object class which allows dynamic adding of attributes and dict-like access to the attributes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages