I can do this:
def f(n):
f.data = 3.14
return n ** 2
f(10), f.data
Out[8]:
(100, 3.14)
My understanding is that in f.data
, the name f
binds to the function object in the outer scope. It looks a bit awkward, but self
doesn't work:
def f(n):
self.data = 3.14
return n ** 2
f(10), f.data
---------------------------------------------------------------------------
NameError: global name 'self' is not defined
Is there an equivalent of self
for referencing function attributes from the inside?