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

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -