猫史档案馆


【Python作品分享】ex17.py【求助帖】

用户:谛霖谛霖查看:6 回复:4 评论:6 创建时间:2023-06-18T17:04:42


【作品展示】

center_image

 

【作品介绍】

《笨办法学python》上的教学程序,一开始是能运行的,运行了几次就报错了,以下是报错内容翻译:

从ss.txt复制到ss.txt

追踪(最近一次通话):

文件“ex17.py”,第10行,在中

indata=in.file.read()

UnicodeDecodeError:“gbk”编解码器无法解码位置2中的字节0x8a:非法的多字节序列

 

【作品源代码】

from sys import argv
from os.path import exists

script, from_file, to_file = argv

print(f"copying from {to_file} to {to_file}")

#we could do these two on one line,now?
in_file = open(from_file)
indata = in_file.read()

print(f'the input file is {len(indata)}bytes long')

print(f'does the output file exist?{exists(to_file)}')
print('ready,hit return to continue, ctrl-c to abort')
input()

out_file = open(to_file, 'w')
out_file.write(indata)

print("alright,all done")

out_file.close()
in_file.close()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
谛霖谛霖

离谱,真的离谱,我重新准备了两个txt文件,然后就行了

点赞0


评论


谛霖谛霖

center_image

点赞0


评论


mornwindmornwind

open函数里加一个encoding="utf-8"(或者你的文档是什么格式)

点赞1


评论


1111111111111111211111111111111112

来我们的工作室吧,永远向python爱好者敞开

点赞0


评论