c[:]()

Mikael Olofsson mikael at isy.liu.se
Thu May 31 04:51:48 EDT 2007


Warren Stringer wrote:
> I want to call every object in a tupple, like so:
> [snip examples]
> Why? Because I want to make Python calls from a cell phone. 
> Every keystroke is precious; even list comprehension is too much. 

If you are going to do this just a few times in your program, I cannot 
help. But: If you want to do it several times, perhaps you have space 
for an initial class definition, like so:

class CallableList(list):
    def __call__(self,*args,**kwargs):
        return [f(*args,**kwargs) for f in self]

def a(): return 'a called'
def b(): return 'b called'
c = CallableList([a,b])()

You might want to trim the class to fit your needs, perhaps use a 
shorter name, and perhaps you don't need to handle arguments. Can the 
class be placed in a module, so that it only needs to be typed once in 
your application?

/MiO



More information about the Python-list mailing list