namespace issue
Daniel Nogradi
nogradi at gmail.com
Fri Apr 14 05:39:58 EDT 2006
> def _gn(x):
> return x.upper()
>
> great_name = _gn
>
> class myclass:
> def mymethod(self, great_name=False):
> if great_name:
> return _gn('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'
Thanks a lot for both suggestions, they were the things I was looking for.
More information about the Python-list
mailing list