如何使用用户input()
函数在Python 3.6.x中读取整个文件?就像算法挑战网站所做的那样。例如:
I have a file with the following content:
line 1 line 2 line 3 end
My program would do something like:
x = input() while x != 'end': print("I am at", x) x = input()
Then I would have as output:
I am at line 1 I am at line 2 I am at line 3
我想我需要用另一个程序(可能是Python或操作系统脚本)包装我的Python示例程序,并将文件作为用户输入传递给第一个程序。但是我应该如何实现呢?