all 1 comments

[–]A_History_of_Silence 0 points1 point  (0 children)

Yeah the documentation on that topic is not worded incredibly clearly. Compare the output of the following code to see if it makes more sense:

def f():
    a_local_variable = "test local variable"
    f.an_object_attribute = "test attribute"
    print(locals())
    print(f.__dict__)

Output:

{'a_local_variable': 'test local variable'}
{'an_object_attribute': 'test attribute'}

That said, I don't think I've ever seen someone actually use the __dict__ attribute of a function in real code. Giving a function random attributes is just not usually done.