I have a script, client.py, that reads command line args straight as a script (not wrapped in a function like main()), like so:
opts, args = getopt.getopt(sys.argv[1:], "l:r:a:j:b:f:n:u:")
and prints a bunch of stuff.
I need to call this script from my code (on Google App Engine, if that matters). It seems that calling
import client
runs client.py as a script, but how do I specify the arguments?
You shouldn’t do this unless you have to: if you have two Python scripts they can communicate in Python instead of through a command line parser. Rewrite
client.pywith anif __name__ == "__main__"check and then call its main function directly from your script.If you don’t have the option of doing that (and you should avoid this case if at all possible), you might be able to set
sys.argv; I’m not sure if GAE allows you to do that. YOu may also be able to usesubprocess.Popen.