[Tutor] errno module - was File copying - best way?
Kalle Svensson
kalle@gnupung.net
Sun, 5 Aug 2001 20:33:43 +0200
Sez fleet@teachout.org:
>
> I will study this and look at the rest of the exceptions listed for 'os;'
> but what about the 'errno' module?
The errno module is used for mapping a error code set by a failed C system
call to a name and the other way around:
>>> try:
... f = open("/usr/testfile", "w")
... except IOError, e:
... pass
...
>>> e
<exceptions.IOError instance at 0x81103a4>
>>> dir(e)
['args', 'errno', 'filename', 'strerror']
>>> errno.errorcode[e.errno]
'EACCES'
>>> errno.EACCES
13
>>> errno.EACCES == e.errno
1
>>> print e
[Errno 13] Permission denied: '/usr/testfile'
>>>
Peace,
Kalle
--
Free Dmitry Sklyarov! - http://www.freesklyarov.org/