Is this considered black magic?

Tim Peters tim.one at home.com
Sun Nov 11 12:59:11 EST 2001


[Laura Creighton]
> ...
> def foreach(name_key, object_list, *args):
>     print 'foreach: args are ' + `args`
>     for object in object_list:
>         try:
>             object.__class__.__dict__[name_key](object, *args)
>         except KeyError:
>             pass
> ...
> But is it white, grey, or black magic?

Playing with __dict__ is black magic.  Playing with getattr() is white
magic.  Putting too much inside a "try" clause is merely suicidal <wink>.





More information about the Python-list mailing list