这曾经在 Linux 下运行良好。在 Windows ( Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:23:52) [MSC v.1900 32 bit (Intel)] on win32
) 下,我收到以下错误:
Need to process 1 file(s)
Processing file test01.toml (1 of 1)
Traceback (most recent call last):
File "py/process.py", line 27, in <module>
add_text_fragment(input_dir + "/" + file)
File "<string>", line 10, in add_text_fragment
File "C:\Users\1\Anaconda3\lib\site-packages\toml\decoder.py", line 134, in lo
ad
return loads(f.read(), _dict, decoder)
File "C:\Users\1\Anaconda3\lib\encodings\cp1251.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 985: char
acter maps to <undefined>
我假设错误发生在这里的某个地方:
f = open(toml_file_name, "r")
pt = toml.load(f)
f.close()
根据 NotePad++,有问题的文件有 UTF-8 编码。
我该如何解决?
赏金条款
我将把这个赏金奖励给一个向我展示如何确保脚本process.py正确处理输入文件的人,即执行超出了If at this point pt
以addTextFragment.py开头的注释
def add_text_fragment(toml_file_name):
f = open(toml_file_name, "r")
pt = toml.load(f)
f.close()
# If at this point pt contains dthe data of the input file,
# then you have attained the goal.
if (pt["type"] == "TA"):
并且变量pt
包含来自输入文件的数据。
您的解决方案必须在 Windows 10, Python 3.7.6 下运行(default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
。
注意:对特定目录中的所有文件process.py
执行。addTextFragment.py