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

C# random value from dictionary and tuple -

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

cgi - How do I interpret URLs without extension as files rather than missing directories in nginx? -