Last active
March 8, 2016 13:28
-
-
Save thigm85/82dbe541f29b64e5d8ba to your computer and use it in GitHub Desktop.
Example of using else clause after try ... except clauses in python. Reference: https://docs.python.org/2/tutorial/errors.html#handling-exceptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for arg in sys.argv[1:]: | |
| try: | |
| f = open(arg, 'r') | |
| except IOError: | |
| print 'cannot open', arg | |
| else: | |
| print arg, 'has', len(f.readlines()), 'lines' | |
| f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment