Question about using "with"

Duncan Booth duncan.booth at invalid.invalid
Tue Jan 9 13:43:58 EST 2007


Laszlo Nagy <gandalf at designaproduct.biz> wrote:

> 
>>
>> 591 > ./cat.py cat.py
>>    File "./cat.py", line 6
>>      with open(sys.argv[nn]) as f:
>>              ^
>> SyntaxError: invalid syntax
>> 592 >
>>
>> This example came from http://docs.python.org/tut/node10.html down in 
>> section 8.7
>>
>> Am I missing something?
>>   
> Are you using python 2.5? The with statement is not available before 2.5.
> 
and even in Python 2.5 it isn't available unless you enable it. Add the 
following line before the 'import sys' line:

from __future__ import with_statement



More information about the Python-list mailing list