Is this considered black magic?
Martin von Loewis
loewis at informatik.hu-berlin.de
Sun Nov 11 10:11:41 EST 2001
Laura Creighton <lac at strakt.com> writes:
> object.__class__.__dict__[name_key](object, *args)
I would write this as
getattr(object, name_key)(*args)
If you read it aloud, you should say "get me the method(*) name_key of
object, and call it with args". That is not much magic.
HTH,
Martin
(*) It doesn't have to be a method. If it is not, calling it will
likely fail.
More information about the Python-list
mailing list