osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FDs will be closed after exception automatically in python2.7?


On 2019-06-10 10:48, Michael Torrie wrote:
> Probably you should be using Python 3, which uses a print() function.
> But even in Python 2.7, the recommended way to do this is like this:
> 
> fd = open("file","w+")
> with fd:

There is still a small window there if there are asynchronous events
happening.  Use this instead:

with open("file","w+") as fd:

*rest of good advice elided.*

-- 
D'Arcy J.M. Cain
Vybe Networks Inc.
http://www.VybeNetworks.com/
IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com