What is func_dict?

If I make a simple function in python, it has both __dict__ and func_dict as attributes, both of which begin as empty dictionaries:

 >>> def foo(): ... return 42 ... >>> foo.__dict__ {} >>> foo.func_dict {} 

If I add the attribute to foo , it will appear 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 case of using one over the other?

+5
source share
1 answer

They are aliases for the same base dict. You should use __dict__ since func_dict missing in Python 3.

+8
source

All Articles