wasm-demo/demo/ermis-f/python_m/cur/1625

36 lines
967 B
Plaintext

From: gornauth at dds.nl (Gornauth)
Date: Fri, 23 Apr 1999 15:37:20 +0200
Subject: opening more than 1 file
References: <371CB255.5FCAFBAF@solair1.inter.NL.net> <371CCAE0.7DE87F8A@aw.sgi.com>
Message-ID: <7fpteh$cik$1@news1.xs4all.nl>
X-UID: 1625
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