简体   繁体   English

我可以在运行python之前编写多行输入吗?

[英]Can I write inmultiple lines of input before I run python?

Can I do make a program accept many lines of prewritten input, something like this?我可以让程序接受多行预写的输入,像这样吗?

596
481
888

Yes, all you have to do is the following:是的,您所要做的就是:

import sys

for arg in sys.argv:
     print(arg)

Then when you run your program all you have to do is supply it command line arguments.然后当你运行你的程序时,你所要做的就是提供命令行参数。 Here is how that works:这是它的工作原理:

python script.py foo bar baz

This will output:这将输出:

foo
bar
baz

This is known as passing command line arguments.这称为传递命令行参数。 Hope this helped you.希望这对你有帮助。

Just as some friendly advice I'd like to say that it is best to try to find the answer yourself first before posting here.就像一些友好的建议一样,我想说最好先尝试自己找到答案,然后再在这里发帖。 (If you did that and you weren't able to then it is fine.) (如果你这样做了,但你做不到,那也没关系。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM