Skip to content

Instantly share code, notes, and snippets.

@g1eb
Created April 6, 2020 19:59
Show Gist options
  • Save g1eb/a2c9e7ce0053eba2b7bb467e65df552e to your computer and use it in GitHub Desktop.
Save g1eb/a2c9e7ce0053eba2b7bb467e65df552e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys, errno
if __name__ == "__main__":
try:
with open(sys.argv[1]) as f:
s = f.read()
print('read', len(s), 'bytes.')
except IOError as x:
if x.errno == errno.ENOENT:
print(sys.argv[1], '- does not exist')
elif x.errno == errno.EACCES:
print(sys.argv[1], '- cannot be read')
else:
print(sys.argv[1], '- some other error')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment