Python - Run function with parameters in command line -


is possible run python script parameters in command line this:

./hello(var=true) 

or mandatory this:

python -c "from hello import *;hello(var=true)" 

the first way shorter , simpler.

most shells use parentheses grouping or sub-shells. can't call commands command(arg) normal shell ...but can write python script (./hello.py) takes argument.

import optparse parser = optparse.optionparser() parser.add_option('-f', dest="f", action="store_true", default=false) options, remainder = parser.parse_args() print ("flag={}".format(options.f))  

and call python hello.py -f


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

android - CoordinatorLayout, FAB and container layout conflict -