【发布时间】:2013-02-09 17:07:14
【问题描述】:
我编写了以下代码,目的是将 abc.txt 的内容复制到另一个文件 xyz.txt 中
但声明 b_file.write(a_file.read()) 似乎没有按预期工作。如果我用某个字符串替换 a_file.read(),它(字符串)会被打印出来。
import locale
with open('/home/chirag/abc.txt','r', encoding = locale.getpreferredencoding()) as a_file:
print(a_file.read())
print(a_file.closed)
with open('/home/chirag/xyz.txt','w', encoding = locale.getpreferredencoding()) as b_file:
b_file.write(a_file.read())
with open('/home/chirag/xyz.txt','r', encoding = locale.getpreferredencoding()) as b_file:
print(b_file.read())
我该怎么做?
【问题讨论】:
标签: python python-3.x file-handling