On Mon, Aug 16, 2010 at 12:29 AM, Gary Herron
wrote:
> On 08/16/2010 12:06 AM, Alan wrote:
>> Hello,
>> I am using things like:
>> with open("myfile.txt") as f:
>> for line in f:
>> print line
>
> You don't need the new fangled with statement if you want to be compatible
> with older
> f = open("myfile.txt")
> for line in f:
> print line
> f.close() # This is what the "with" statement guarantees; so now just do
> it yourself
Not exactly. More like:
f = open("myfile.txt")
try:
for line in f:
print line
finally:
f.close()
Daniel
--
http://mail.python.org/
On 08/16/2010 12:06 AM, Alan wrote:
Hello,
I am using things like:
except Exception as inst:
and
The old syntax for exceptions still works in Python2.x (all versions).
The new syntax works in Python2.6+ and Python3.
try:
whatever
except Exception,msg: # Old syntax
Hello,
I am using things like:
except Exception as inst:
and
with open("myfile.txt") as f:
for line in f:
print line
Things that seems to be new in python 2.6 and higher, however reading
http://docs.python.org/tutorial/errors.html and this not clear when this new
syntaxes appeared.