I personally love using with statements when handling file like objects. This is all well and good until an exception is thrown from the with statement. This is ok if you expect the exception because you can use try and except but personally I feel that another condition to with would feel more 'pythonic' this means that you could fail the with statement with an exception jump to the clause, then jump back to the with statement trying the code in the clause e.g. rather than<div>
<br></div><div>try:</div><div>    with open('nofile.txt','r') as inp:</div><div>        #nofile.txt does not exist and throws an exception</div><div>except IOError:</div><div>    with open('another.txt','r') as inp:</div>
<div>        #carry on where you left off...</div><div><br></div><div>You could simply have</div><div><br></div><div>with open('nofile.txt','r') as inp:</div><div>    #exception here</div><div>else:</div><div>
    #give a new file to the with statement here and/or run some panic code where your program does something to fix the situation.</div><div><br></div><div>It could be a foolish idea as I am only a intermediate user but I thought it might be worth voicing none the less as you don't learn from staying silent.</div>
<div><br></div><div><br></div>