Page 1 of 1

explanations of __dict__ python?

PostPosted: Tue May 19, 2015 2:52 pm
by ghostheadx2
Hi, I found some results for a __dict__ function:

http://pythondoeswhat.blogspot.sg/2012/ ... -vars.html

http://stackoverflow.com/questions/1436 ... -in-python

What I got out of this was, every object is backed up by a __dict__. Alright, but is a __dict__ an object, function, etc? Does it mean a dictionary? What does the __dict__ do? Its an attribute ok, but could someone explain an attribute better please?

I got this out of the docs.python.org:

Code: Select all

Attribute           |      Meaning

__dict__ func_dict  |     The namespace supporting arbitrary function attributes.



Could someone explain? I think this definition means the string or field, etc. that supports something about a function. Again, I know an attribute is a reference to I think the name of a function in a module. So then, it supports certain functions from a module? Is it like the namespace itself?

Re: explanations of __dict__ python?

PostPosted: Wed May 20, 2015 5:21 pm
by cyberdrain
Everything in Python is an object, so yes, this is too. If I recall correctly it's a dictionary of all the variables associated with a module, class or object of a class. Create a class geometric_object that has two integers, a length and a width. Then an object circle derived from geometric_object would have the attributes circle.length and circle.width and both would be set to some integer. Both length and width should be in the __dict__ of both geometric_object and circle.