c[:]()
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Fri Jun 1 22:25:23 EDT 2007
En Fri, 01 Jun 2007 14:22:29 -0300, Warren Stringer <warren at muse.com>
escribió:
> I am not insisting on anything. I use ``c[:]()`` as shorthand way of
> saying
> "c() for c in d where d is a container"
I begin to think you are some kind of Eliza experiment with Python
pseudo-knowledge injected.
Anyway, the code below defines a simple "callable" list; it just calls
each contained item in turn. Don't bother to use [:], it won't work.
py> class CallableList(list):
... def __call__(self):
... for item in self:
... item()
...
py> def a(): print "a"
...
py> def b(): return 4
...
py> def c(): pass
...
py> def d():
... global z
... z = 1
...
py> z="A"
py> x = CallableList([a,b,c,d])
py> x()
a
py> z
1
--
Gabriel Genellina
More information about the Python-list
mailing list