Issue
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 :)
Solution
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
Answered By - Torxed
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.