You know filename, it is the file you were reading and calculating the CRC for. For errno and strerror I would pick from the list of defined errors in libc. This is where the reasons of most IOErrors originate from, so lets keep this implementation detail for consistency. Which values to pick is somewhat arbitrary (and not completely OS independent), I'd try convey the general meaning of my problem without being too specific.
You could take one of these (the comment would be strerror):
EIO 5 /* I/O error */
EINVAL 22 /* Invalid argument */
Being too specific with such a "fake" libc error could send people debugging a problem on the wrong track.
BTW I consulted this list for existing errno's
IOError exception (in Python 2.7.2?
GreenFileDescriptorIO.seek should raise IOError, not OSError
Error "raise IOError(text)" when transfer file
Raising builtin exception with default message in python - Stack Overflow
Hello, I am trying to read from the .gz file and it is giving me the following error. Below are the code and traceback.
f = glob.glob (*/.gz)
if f:
for files in f:
with zgip.open(files, 'r') as r:
for line in r:
for i in range (3):
print lineTraceback:
Traceback (most recent call last):
File "tst.py", line 14, in <module>
for line in r:
File "python2.7/gzip.py", line 446, in readline
c = self.read(readsize)
File "python2.7/gzip.py", line 252, in read
self._read(readsize)
File "python2.7/gzip.py", line 287, in _read
self._read_gzip_header()
File "python2.7/gzip.py", line 181, in _read_gzip_header
raise IOError, 'Not a gzipped file'
IOError: Not a gzipped filePlease help me in solving this.
import os
try:
open('foo')
except IOError as err:
print(err)
print(err.args)
print(err.filename)
produces
[Errno 2] No such file or directory: 'foo'
(2, 'No such file or directory')
foo
So, to generate an OSError with a similar message use
raise OSError(2, 'No such file or directory', 'foo')
To get the error message for a given error code, you might want to use os.strerror:
>>> os.strerror(2)
'No such file or directory'
Also, you might want to use errno module to use the standard abbreviations for those errors:
>>> errno.ENOENT
2
>>> os.strerror(errno.ENOENT)
'No such file or directory'