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
Post a Comment