Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 Windows 终端中,一种类型:python3 program.py<input_file.txt使用文本输入文件运行程序。我是 Linux 新手,我已经尝试过了,但我得到了错误:
python3 program.py<input_file.txt
File "<string>", line 1, in <module>
关于为什么将我的输入文件作为字符串读取的任何建议?任何帮助将不胜感激!
胡乱猜测。您在 Windows 中使用 python3,但在 Linux 中使用 python2。此外,您input()的程序中有一个函数调用。您陷入了 python2 和 python3 之间不兼容的更改。
input()
python -V您可以通过在每个环境中运行来证实我的怀疑。
python -V
如果我是对的,您可以通过将您的替换为 或在 Linux 上安装 python3 来解决input()问题raw_input()。
raw_input()