A simple example is like this:
class abs_obj:
def __init__(self, acceptType = abs_obj):
# do something
pass
which gives the error message:
NameError: name 'abs_obj' is not defined
Any suggestions?
A simple example is like this:
class abs_obj:
def __init__(self, acceptType = abs_obj):
# do something
pass
which gives the error message:
NameError: name 'abs_obj' is not defined
Any suggestions?
The issue here is that the class isn't actually created until after all of its methods have been compiled, but default values are calculated once at compile time.
It might be possible to specify a different default value, and change it to the desired value afterwards by manipulating the function's func_defaults attribute. But this is ugly, and not guaranteed to work in all Python implementations.
The more usual way to solve a problem like this would be:
def __init__(self, acceptType = None):
if acceptType is None:
acceptType = abs_obj
# do something
pass
If None was a valid value for the parameter, you'd have to choose some other value as the default.