I have a piece of code where I pull a function out of a dictionary, then add an object attribute to it. However I am having some problems accessing it from within the function, presumably due to the namespace.
aFunction = FunctionsDictionary[key]
aFunction.someObject = someObject
aFunction()
def aFunction():
someObject.doSomething()
Gives NameError global name 'someObject' is not defined.
If I do a dir(aFunction) after I set the attribute I can see it, however a dir() from within the function does not show the attribute.
Although I can likely change the code to have the function accept the object as an argument, how do I refer to these attributes set on the 'instance' of the function?
Here is another example:
def myFunc():
print coolAttr
func = myFunc
func.coolAttr = "Cool Attribute"
func()
NameError: global name 'coolAttr' not defined