在该练习中,按照作者列出的代码逐字输入,依然会出现如下的报错。
Traceback (most recent call last):
File "ex17.py", line 10, in <module>
indata = in_file.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xff in position 0: illegal multibyte sequence
> https://ask.csdn.net/questions/668913
我在这个网页中我找到了答案。
该答主使用New-Item来创建txt文件。他还用 Atom 打开两个 txt 进行对比,发现用 echo 命令创建的以两个菱形的问号��开头,且每个英文字母间还多了一个空格;但New-Item 创建的txt只有输入的那一行英文。
因此,解决方案就是在Windows Powershell中使用New-Item创建txt文件,并录入内容,就不会报错。
New-Item sun.txt -type file -value "This is a test file."