python可以让用户输入的信息是_一种Python脚本提供“用户输入”信息,到另一个python脚本...

this is my first question, I hope I'm doing this right.

let's say I have these this file:

"simple.py":

a=raw_input("your name?")

print "Hello",a

but with a different script, I want to execute "simple.py" many time and giving the input automatically, that would work like:

"everyone.py"

run simple.py input=Alice

run simple.py input=Bob

...

to get

"Hello Alice"

"Hello Bob"

...

I know it's possible to make "everyone.py" run "simple.py" by using os.system, but is there any practical way to do something like this? And what if the first script asks for input several times?

It's important that I CANNOT EDIT SIMPLE.PY, only the other file

Thanks in advance :)

解决方案import sys

print "Hello",sys.argv[1]

running C:\Python26\python.exe simple.py Alice would produce

Hello Alice

There's a good example on how to get input from the system into a python application here:

Since you didn't mention that you can not modify simple.py then you would need to automaticly input things into the raw_input() and the fastest way to do this is simply to pipe in data into the script as "input":

C:> echo "Alice" | run simple.py

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值