explanations of __dict__ python?

Put your programming skills to the test in these challenges.

explanations of __dict__ python?

Post by ghostheadx2 on Tue May 19, 2015 2:52 pm
([msg=88121]see explanations of __dict__ python?[/msg])

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?
Posts: 728
Joined: Wed Nov 19, 2014 1:19 am
Blog: View Blog (0)

Re: explanations of __dict__ python?

Post by cyberdrain on Wed May 20, 2015 5:21 pm
([msg=88133]see Re: explanations of __dict__ python?[/msg])

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.
Free your mind / Think clearly
User avatar
Posts: 2160
Joined: Sun Nov 27, 2011 1:58 pm
Blog: View Blog (0)

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests