Shutil 将文件保存为文件类型而不是 .txt
我使用以下代码使用 Shutil 将几个 .txt 文件加入到一个文件中。保存的文件保存为“文件”格式,但我可以用记事本打开它。如何直接将文件保存为.txt?
#Join generated text files to one file
import shutil
with open(img_file,'wb') as wfd:
for f in out_file_list:
with open(f,'rb') as fd:
shutil.copyfileobj(fd, wfd)
I am using the following code to join a few .txt files to one file using Shutil. The saved file is saved as a 'File' format, but I can open it with Notepad. How can I save the file to .txt directly?
#Join generated text files to one file
import shutil
with open(img_file,'wb') as wfd:
for f in out_file_list:
with open(f,'rb') as fd:
shutil.copyfileobj(fd, wfd)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@FoundAbetterName 的解决方案按预期工作。谢谢你!
The solution from @FoundAbetterName works as intended. Thank you!