How to run Python functions from command line?

PythonServer Side ProgrammingProgramming

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
raja
Published on 07-Dec-2017 15:10:19
Advertisements