我想讀在它韓文和英文TXT文件。
下面是一個例如:
52:15問候。 안녕하십니까。閱讀TXT文件成Python 3.5,韓文和英文字符在它
我的代碼是:
# Read a line and Split into tokens
f = open(infile, 'r')
for line in f:
if(matchObj = re.match(r"(\d\d:\d\d)\t([^\t]+)\t(.*)$", line)
startTC, englishSubtitle, foreignSubtitle = matchObj.group(1), matchObj.group(2), matchObj.group(3)
else:
SyntaxError(line)
當我在2012年的MacBook Pro運行埃爾卡皮坦讀入蟒(3.5),我得到錯誤信息(在底部)。
錯誤消息:
python3 *.py
Traceback (most recent call last):
File "txtToSrt.py", line 48, in <module>
readFileData("Korean.txt")
File "txtToSrt.py", line 26, in readFileData
for line in f:
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 0: invalid start byte
可否請你建議如何在閱讀本
'0xfe' - 它可以是[BOM(https://en.wikipedia.org/wiki/Byte_order_mark) – furas