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