Tools, FAQ, Tutorials:
Where Are Class Properties Stored
Where Are Class Properties Stored?
✍: FYIcenter.com
Class properties are stored in a built-in property called "__dict__" in class "type" object.
The "__dict__" property is inherited from the base class "object" and managed by the Python engine.
If you ever forget what class properties are associated with a class, you can always look at the content of the built-in property "__dict__". For example:
>>> class user():
... nextID = 1
... def __init__(self,name="Joe",age=25):
... self.id = user.nextID
... self.name = name
... self.age = age
... user.nextID = user.nextID + 1
...
>>> user.instanceCount = 0
>>> user.__dict__
mappingproxy({'__module__': '__main__', 'nextID': 12, '__init__': <function
use .__init__ at 0x01E37300>, 'dump': <function user.dump at 0x01E372B8>,
'__dict__ : <attribute '__dict__' of 'user' objects>, '__weakref__':
<attribute '__weakre __' of 'user' objects>, '__doc__': None,
'instanceCount': 2})
The output shows that other information about the class is also stored in the built-in property "__dict__" of the class "type" object.
⇒ Create New Instances of a Class
⇐ Manage and Use Class Properties
2018-01-27, ∼1796🔥, 0💬
Popular Posts:
Tools, FAQ, Tutorials: JSON Validator JSON-XML Converter XML-JSON Converter JSON FAQ/Tutorials Pytho...
How to access Query String parameters from "context.Request.Url.Que ry"object in Azure API Policy? Q...
Can Multiple Paragraphs Be Included in a List Item? Yes. You can include multiple paragraphs in a si...
How to use the "send-one-way-request" Policy statement to call an extra web service for an Azure API...
What is Azure API Management Gateway? Azure API Management Gateway is the Azure Web server that serv...