c[:]()

Warren Stringer warren at muse.com
Thu May 31 02:23:22 EDT 2007


Oops! guess I should have tested my rather hasty complaint about executable
containers. This is nice:

def a(): return 'b'
def b(): print 'polly! wakey wakey'
c = {}
c['a'] = b
c[a()]()  #works!


c[a()]() is a switch statement with an amorphous selector- very handy in its
own right. But, using a() as a generator would be more expressive. This
seems to work:

c = [a,a]
[d() for d in c]

But that still isn't as simple or as direct as:

c[:]()

Which would you rather explain to a 12-year-old writing code for the first
time?

> I still want my executable container though. Would love to so this
> 
> h[search('a//f')]()   # where a//f is like an Xpath // search for leaves
> 





More information about the Python-list mailing list