I have a script foobar.py with this code
# file foobar.py def sayHello(): return 'Hello'
How do I run the python function in the script from the command line?
To run this function from the command line we can use the -c (command) argument as follows:
$ python -c 'import foobar; print foobar.sayHello()'
Alternatively, we can also write:
$ python -c 'from foobar import *; print sayHello()'
Or like this
$ python -c 'from foobar import sayHello; print sayHello()'
OUTPUT
Hello
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more