I would like to give the same name to a keyword argument of a class
method as the name of a function, with the function and the class
living in the same namespace and the class method using the
aforementioned function. So far I've been unsuccesfully trying to go
along these lines:
def great_name( x ):
return x.upper( )
class myclass:
def mymethod( self, great_name=False ):
if great_name:
return great_name( 'something' )
else:
return 'something'
This would fail, because in the namespace of mymethod great_name is a
local variable and is not a callable. So I tried to modify the class
like this:
class myclass:
def mymethod( self, great_name=False ):
great_name_ = great_name
del great_name
if great_name_:
return great_name( 'something' )
else:
return 'something'
in the hope of the del statement only removing the local variable util
but still remembering the great_name function from outside, but this
didn't work either. So my question is if it was possible to do this at
all?
The reason for giving the same name is a usability issue of my module,
I would like both the keyword argument and the function to be visible
by the user and the name I would like to give them describes very well
what they are doing. That is also the reason why I don't want to hide
the great_name function in the class as a method.