小编Bis*_*its的帖子

Python AttributeError:NoneType 对象没有属性“close”

我正在学习 python,我编写了一个脚本,将一个文本文件的内容复制到另一个文本文件。

这是我的代码。

from sys import argv
out_file = open(argv[2], 'w').write(open(argv[1]).read())
out_file.close()
Run Code Online (Sandbox Code Playgroud)

我得到标题上列出的 AttributeError 。为什么当我在 open(argv[2], 'w') 上调用 write 方法时,out_file 没有分配 File 类型?

先感谢您

python file attributeerror

5
推荐指数
1
解决办法
3万
查看次数

标签 统计

attributeerror ×1

file ×1

python ×1