Reputation: 303107
If I make a simple function in python, it has both __dict__
and func_dict
as attributes, both of which start out as empty dictionaries:
>>> def foo():
... return 42
...
>>> foo.__dict__
{}
>>> foo.func_dict
{}
If I add an attribute to foo
, it shows up in both:
>>> foo.x = 7
>>> foo.__dict__
{'x': 7}
>>> foo.func_dict
{'x': 7}
What is the difference between these attributes? Is there a specific use-case of one over the other?
Upvotes: 6
Views: 2239
Reputation: 280963
They're aliases for the same underlying dict. You should use __dict__
, since func_dict
is gone in Python 3.
Upvotes: 10