+ 9

[Python] A function attribute is not a local?

Where do I find f.a? https://code.sololearn.com/c39Elhwdu0hE/?ref=app

1st May 2021, 6:17 AM
Oma Falk
Oma Falk - avatar
4 Respostas
+ 7
function attributes are not local variables, but are added to the func_dict for the function in a key : value relationship. They can be accessed via the __dict__ of the function. print(fun.__dict__) https://www.python.org/dev/peps/pep-0232/
1st May 2021, 6:45 AM
ChaoticDawg
ChaoticDawg - avatar
+ 4
https://docs.python.org/3.9/reference/datamodel.html#objects-values-and-types Scroll down to callable types. Also, lookup __dict__ The PEP is probably the most informative from what I've seen.
1st May 2021, 7:30 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
ChaoticDawg thanks! you have a docu for it?
1st May 2021, 6:56 AM
Oma Falk
Oma Falk - avatar
+ 2
Mirielle yes. f.a is different to b. And thinking about the difference and locals() akes everything a bit clearer.
1st May 2021, 8:51 AM
Oma Falk
Oma Falk - avatar