Ubuntu Pastebin

Paste from smoser at Mon, 15 Aug 2016 20:48:52 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
$ cat /tmp/my.py 
import errno
import sys
try:
  open(sys.argv[1])
except (OSError, IOError) as e:
    print("Actual class is %s" % e.__class__)
    print("errno is %s" % getattr(e, "errno"))
    if getattr(e, 'errno', None) == errno.ENOENT:
       print("just a no such file or directory")
$ 
$ python3 /tmp/my.py /tmp/enoexistdirfoo/bar
Actual class is <class 'FileNotFoundError'>
errno is 2
just a no such file or directory
Download as text