On Wed, Apr 10, 2013 at 4:45 PM, Albert-Jan Roskam <fo...@yahoo.com> wrote:
>
>> with open('old.dat') as fin, open('new.dat', 'w') as fout:
>
> Is that Python 3.x?

It's the same syntax as an import statement such as the following:

    import numpy as np, matplotlib as mpl

A downside with this is the inability to split long lines by adding
parentheses. Obviously you can break at the open() call:

    with open('old.dat') as fin, open(
     'new.dat', 'w') as fout:
        for line in fin:

But I think it's more readable to break up a long line like this:

    fin = open('old.dat')
    fout = open('new.dat', 'w')

    with fin, fout:
        for line in fin:
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to