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?
They're aliases for the same underlying dict. You should use __dict__
, since func_dict
is gone in Python 3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With