Python - Run function with parameters in command line
Question: Is it possible to run a python script with parameters in command line like
this:

    
    
    ./hello(var=True)
    

or is it mandatory to do like this:

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

The first way is shorter and simpler.


Answer: Most shells use parentheses for grouping or sub-shells. So you can't call any
commands like `command(arg)` from a normal shell ...but you can write a python
script (./hello.py) that takes an 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 the call it with `python hello.py -f`

