One Python script giving "user input" to another python script
automation, input, python, python-2.x
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:
- http://www.tutorialspoint.com/python/python_command_line_arguments.htm
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
Problem
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 :)