On 2013-10-19, at 08:38 , Nick Coghlan wrote: >> The above example, especially if extended beyond two files, begs to used in >> a loop, like your 5 line version: >> >> >> for name in ("somefile.tmp", "someotherfile.tmp"): >> with suppress(FileNotFoundError): >> os.remove(name) >> >> which would be fine, of course. >> >> But to some with less education about the how and why, it is not clear why >> it couldn't be written like: >> >> with suppress(FileNotFoundError): >> >> for name in ("somefile.tmp", "someotherfile.tmp"): >> os.remove(name) >> >> yet to the cognoscenti, it is obvious there are seriously different >> semantics. > > However, that's a confusion about exception handling in general, not > about the suppress context manager in particular. The same potential > for conceptual confusion exists between: > > for name in ("somefile.tmp", "someotherfile.tmp"): > try: > os.remove(name) > except FileNotFoundError: > pass > > and: > > try: > for name in ("somefile.tmp", "someotherfile.tmp"): > os.remove(name) > except FileNotFoundError: > pass It could work if the exceptions system was extended to a full-blow conditions system though.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4