Daniel Nogradi wrote: > 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' >
>>> def great_name(x): ... return x.upper() ... >>> class myclass(object): ... def mymethod(self, great_name=False): ... if great_name: ... return globals()['great_name']('something') ... else: ... return 'something' ... >>> myclass().mymethod() 'something' >>> myclass().mymethod(True) 'SOMETHING' STeVe -- http://mail.python.org/mailman/listinfo/python-list