ファイルエンコーディングを認識するためにchardetを使用していますが、このエラーが発生しました:
fh= open("file", mode="r")
sc= chardet.detect(fh)
Traceback (most recent call last):
File "/home/alireza/test.py", line 19, in <module>
sc= chardet.detect(fh)
File "/usr/lib/python3/dist-packages/chardet/__init__.py", line 24, in detect
u.feed(aBuf)
File "/usr/lib/python3/dist-packages/chardet/universaldetector.py", line 65, in feed
aLen = len(aBuf)
TypeError: object of type '_io.TextIOWrapper' has no len()
エンコーディングがわからないとファイルを開くことができません。
fh= open("file", mode="r").read()
sc= chardet.detect(fh)
Traceback (most recent call last):
File "/home/alireza/workspacee/makecdown/test.py", line 21, in <module>
fh= open("910.srt", mode="r").read()
File "/usr/lib/python3.2/codecs.py", line 300, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc7 in position 34: invalid continuation byte
ファイルを開かずにchardetを使用する方法?!または開く後/開く前にファイルエンコーディングを見つける方法はありますか?