Computer >> Computer tutorials >  >> Programming >> Python

How to run Python functions from 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