shell - how to call a python function and give its parameters from the command line? -
let's say, have python script (test.py) , contains function takes string , printed back, following
def pri(str): print str how call function (pri) command line? tried:
$python test.py pri(blablalba) but got following error: missing end of string
you should use sys.argv. argv list of arguments passed through command line.
try this:
import sys def pri(s): print s pri(sys.argv[1]) and can run doing python test.py blablabla
Comments
Post a Comment