RawIOBase.__init__
does not take any arguments, that is where you error is.
Your TiffFile
implementation also inherits file
which is not a a class, but a constructor function, so your Python 2 implementation is non-idiomatic, and someone could even claim it is wrong-ish. You should use open
instead of file
, and in a class context you should use an io
module class for input and output.
You can use open
to return a file object for use as you would use file
in Python 2.7 or you can use io.FileIO
in both Python 2 and Python 3 for accessing file streams, like you would do with open
.
So your implementation would be more like:
import io
class TiffFile(io.FileIO):
def __init__(self, name, mode='r+b', *args, **kwargs):
super(TiffFile, self).__init__(name, mode, *args, **kwargs)
This should work in all currently supported Python versions and allow you the same interface as your old implementation while being more correct and portable.
Are you actually using r+b
for opening the file in read-write-binary mode on Windows? You should probably be using rb
mode if you are not writing into the file, but just reading the TIFF data. rb
would open the file in binary mode for reading only. The appended +
sets the file to open in read-write mode.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…