python - 如何在 Python 中打开并读取输入文件并将其打印到输出文件?

标签 python file input output

那么我怎样才能要求用户向我提供输入文件和输出文件呢? 我希望将用户提供的输入文件中的内容打印到用户提供的输出文件中。在这种情况下,用户将输入此内容

Enter the input file name: copyFrom.txt
Enter the output file name: copyTo.txt

输入文件中只有文本“hello world”

谢谢。如果可能,请尽可能简单

最佳答案

如果您只想复制文件,shutil 的复制文件会隐式执行循环:

import os
from shutil import copyfile

openfile = input('Enter the input file name:')
outputfile = input('Enter the output file name:')

copyfile(openfile, outputfile)

这个帖子How do I copy a file in Python?了解更多详情

关于python - 如何在 Python 中打开并读取输入文件并将其打印到输出文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54838127/

相关文章:

python - @api.depends 依赖于非存储字段不起作用

python - 从 url 获取图像时出错

Java递归列出特定模式目录中的文件

javascript - 用户输入后加载 Material UI AutoComplete 建议

javascript - 当我添加更多 Material 时,我的内容不会超出一页

python - 如何使用 SVM 预测多类情感分析问题中的所有类?

python - 哪个代码删除了排列中的重复组合

java - 彩票程序(ArrayList)

java - 如何列出当前目录中的文件?

javascript - 检查输入是否有文本并启用按钮