more on "Is this considered black magic?"
Marcin 'Qrczak' Kowalczyk
qrczak at knm.org.pl
Mon Dec 3 07:03:37 EST 2001
More information about the Python-list mailing list
Mon Dec 3 07:03:37 EST 2001
- Previous message (by thread): more on "Is this considered black magic?"
- Next message (by thread): more on "Is this considered black magic?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
3 Dec 2001 10:52:17 GMT, Philip Swartzleonard <starx at pacbell.net> pisze: > Hm, is there something sane that can be done to make 'method' in this > situation a variable? The way i'm designing things, it would be useful to > have a 'call ArbitrayFunction of all X in container' function. I don't see how to make it simpler in Python. This looks less clear than a direct 'for' loop IMHO: def call_method_for(objects, method, *args): for o in objects: getattr(o, method)(*args) call_method_for(objects, 'method', args) There is little to abstract away because there is no good way to express "a method to call". Another approach is to express it with a function: def call_for(objects, f): for o in objects: f(o) call_for(objects, lambda o: o.method(args)) Not an improvement either. -- __("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ QRCZAK
- Previous message (by thread): more on "Is this considered black magic?"
- Next message (by thread): more on "Is this considered black magic?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list