Categories
Python Answers

How to run function from the command line with Python?

Spread the love

Sometimes, we want to run function from the command line with Python.

In this article, we’ll look at how to run function from the command line with Python.

How to run function from the command line with Python?

To run function from the command line with Python, we can run python with the -c flag.

For instance, we run

$ python -c 'import foo; print(foo.hello())'

to run python -c with a string with the code we want to run.

Conclusion

To run function from the command line with Python, we can run python with the -c flag.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *