1. 程式人生 > >python 指令碼讀取檔案時遇到的問題

python 指令碼讀取檔案時遇到的問題

from sys import argv

script,filename=argv

txt=open(filename)

print(f”here is your file {filename}”)
print(txt.read())

然後我在終端執行這個指令碼,然後出現了這樣的情況
zhangxiongdeMBP:practice xzz$ python3.6 zhanghuidongnk.py zhd.txt

here is your file zhd.txt
Traceback (most recent call last):
File “zhanghuidongnk.py”, line 8, in
print(txt.read())
File “/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/codecs.py”, line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0x9b in position 10: invalid start byte
求助大神這究竟是怎麼回事