command - Running python script from within python script -


i new python (c++ fluent) , learning on as-need basis. wrote script takes several arguments , creates , saves matplotlib graph. has no functions, methods, classes, etc. series of instructions results in graph. write script execute script arguments possible.

is possible in python?

take @ stdlib's subprocess module: http://docs.python.org/2/library/subprocess.html

from subprocess import call call([sys.executable, 'script.py', arg1, arg2]) 

for complete list of options take @ similar question: calling external command in python

read docs on link provided above, specially if need call secure (make sure trust or validate params).

update:

as alternative (and better) option run code importing it.

if clean , put in function , import , call main program dont need execute module script and, if need to, still able run standalone script easily:

# script.py def func(param1, param2, param3)     #...  if __name__=="__main__":     # params...     func(param1, param2, param3)     # handle output etc...   # main.py # ... script import func # ... func(param1, param2, param3) # ... 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -