opening more than 1 file

Gornauth gornauth at dds.nl
Fri Apr 23 09:37:20 EDT 1999


Gary Herron wrote in message <371CCAE0.7DE87F8A at aw.sgi.com>...

>If your definition of `elegant' includes `short', here is a one-liner to
>do this. It maps a list [0,1,2,...] to a list of open files:
>
>[<open file 'file00', mode 'w' at 100bb2e8>,
> <open file 'file01', mode 'w' at 100bb338>,
> <open file 'file02', mode 'w' at 100bb388>,
> ...]
>
>files = map(lambda i: open("file%02d"%i, 'w'), range(N))

I'm not completely sure how that one-liner works. To be honest, I have no
clue whatsoever.

Could someone more python-literate please be so kind as to give a couple of
examples on how to use 'map' and 'lamba'?

Met vriendelijke groeten,
        Hans








More information about the Python-list mailing list