Technically it would be equivalent to try: os.unlink(filename) except IOError: pass
one could define OSError= IOError and from future import with_statement, then define ignore(...). It is not difficult but slower than the above syntax. I prefer if os.path.exists(filename). On Monday, 22 July 2013 10:35:03 UTC-5, Richard wrote: > > Thanks for sharing Simone! > > Appreciate! > > I notice one change that can improve web2py, but not seems available in > python 2.7 : > > with ignore(OSError): > os.unlink(filename) > > In replacement to : > > if os.path.exists(filename): > os.unlink(filename) > > > https://speakerdeck.com/pyconslides/transforming-code-into-beautiful-idiomatic-python-by-raymond-hettinger-1?slide=37 > http://mmoya.org/blog/2013/03/17/python-gets-a-new-ignored-context-manager/ > > Seems that there is a small risk of concurent access with os.path.exists() > and os.unlink() > > http://stackoverflow.com/questions/10840533/most-pythonic-way-to-delete-a-file-which-may-not-exist > > :) > > Richard > > > > > On Sun, Jul 21, 2013 at 6:07 PM, Niphlod <nip...@gmail.com > <javascript:>>wrote: > >> I actually skipped over this a few times and today I finally reached its >> place in my playlist for free time... sorry if you seen it before, but I >> actually learned at least 5 things out of it that I reaaaaally didn't know >> of. >> >> https://www.youtube.com/watch?v=OSGv2VnC0go >> >> if you want slides >> >> >> https://speakerdeck.com/pyconslides/transforming-code-into-beautiful-idiomatic-python-by-raymond-hettinger-1 >> >> -- >> >> --- >> You received this message because you are subscribed to the Google Groups >> "web2py-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to web2py+un...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.