Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将多行作为输入传递给stdin(Python)_Python_Eclipse_Stdout_Stdin - Fatal编程技术网

如何将多行作为输入传递给stdin(Python)

如何将多行作为输入传递给stdin(Python),python,eclipse,stdout,stdin,Python,Eclipse,Stdout,Stdin,假设示例输入为: "1 2 3" "hello" "hi there" "x y z" "5 6 7" 这应该被传递到stdin,输出应该只是将它们打印到stdout 我在sample.py中有以下代码,并且我使用Eclipse作为我的IDE import fileinput for line in fileinput.input(): print line 如果我使用命令行,我可能可以执行以下操作 python sample.py "1 2 3 \n hello" 将输入传递到

假设示例输入为:

"1 2 3"
"hello"
"hi there"
"x y z"
"5 6 7"
这应该被传递到stdin,输出应该只是将它们打印到stdout

我在sample.py中有以下代码,并且我使用Eclipse作为我的IDE

import fileinput

for line in fileinput.input():
    print line
如果我使用命令行,我可能可以执行以下操作

python sample.py "1 2 3 \n hello"
将输入传递到标准输入。但是我应该如何在Eclipse上做到这一点(当有多行代码应该输入到stdin中时)


因为我不知道怎么做,我只是把这些行放到一个txt文件中并从中读取。

在Windows上

  • 将Python目录添加到环境变量路径(例如C:\Python27)
  • 将所有行放入某个文本文件(例如,input.txt应包含“hello\n hello”)
  • 运行
    cmd
  • 转到源代码和输入文件所在的目录
  • 运行
    python sample.py
  • 然后在
    stdout
    中得到一个输出

    在Windows上

  • 将Python目录添加到环境变量路径(例如C:\Python27)
  • 将所有行放入某个文本文件(例如,input.txt应包含“hello\n hello”)
  • 运行
    cmd
  • 转到源代码和输入文件所在的目录
  • 运行
    python sample.py
  • 然后在
    stdout
    中得到一个输出