I was wondering how to properly keep a static object in a python class. In this case I want to have a static dictionary
Just a simple example of what I'm looking for:
class dTest:
# item I want to be static
d = {"First":1}
>>> a = dTest()
>>> a.d
{'First': 1}
>>> dTest.d["Second"] = 2
>>> a.d["Third"] = 3
>>> a.d
{'Second': 2, 'Third': 3, 'First': 1}
>>> dTest.d
{'Second': 2, 'Third': 3, 'First': 1}
Now if I directly call the class and replace d with a new dictionary
>>> dTest.d = {}
>>> a.d
{}
However I'd also like to have the same functionality if I replace a.d with a new dictionary
>>> a.d = {"Fourth":4}
>>> a.d
{'Fourth': 4}
>>> dTest.d
{}
My desired result right now would be for dTest.d to be the same to a.d (dTest.d being {'Fourth': 4}).
Is there a proper practice for this, or do I have to just make sure I only ever edit the object if I do it from an instance of dTest?
Thanks!
propertyto create getters and settersdTest.dafter you have changeda.dand you will notice thata.dwill no longer change along withdTest.d.dthru the class...