with block for multiple files
Chris Rebert
clp2 at rebertia.com
Mon Nov 1 01:10:25 EDT 2010
On Sun, Oct 31, 2010 at 10:03 PM, Yingjie Lan <lanyjie at yahoo.com> wrote:
> Hi,
>
> Suppose I am working with two files simultaneously,
> it might make sense to do this:
>
> with open('scores.csv'), open('grades.csv', wt) as f,g:
> g.write(f.read())
>
> sure, you can do this with nested with-blocks,
> but the one above does not seem too complicated,
> it is like having a multiple assignment...
>
> Any thoughts?
Guido's time machine strikes again! It's already in Python 3; your
example would be spelled:
with open('scores.csv') as f, open('grades.csv', wt) as g:
g.write(f.read())
Cheers,
Chris
--
Where does GvR source his flux capacitors from?
http://blog.rebertia.com
More information about the Python-list
mailing list