To 'with' or not to 'with': how is the question ?

Huaiyu Zhu hzhu at yahoo.com
Tue Sep 5 20:55:34 EDT 2000


On Sun, 03 Sep 2000 21:42:33 +0200, Daniel Dittmar <daniel at dittmar.net>
wrote: 
>Writing a 'for' when you don't have a loop seems really confusing (just
>because it executes the same dosn't mean it it easily recognized as
>such).

It is in fact very handy in this particular case - I often use this to
simulate the effect of tee, with much higher flexibility, like

#outfiles = [sys.stdout]
outfiles = [sys.stdout, file]
for out in outfiles:
    out.write(result)

You can easily manipulate this during the coding/debugging cycle.
You can also pass in outfiles from argument list, etc.

Huaiyu



More information about the Python-list mailing list