- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
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()'
- Related Articles
- How to run Python functions in Eclipse command line?
- How to run TestNG from command line?
- How to run a specific group of tests in TestNG from command line?
- How to call Python module from command line?
- How to Pretty print Python dictionary from command line?
- How to run PowerShell commands from the command prompt?
- How to read a file from command line using Python?
- Run a Function in a Script from the Command Line on Linux
- How to write into a file from command line using Python?
- How to run a PowerShell script from the command prompt?
- How to upgrade MySQL server from command line?
- How to Pretty-Print XML From Command Line?
- How to do Python math at command line?
- How to add command line arguments in Python?
- How to repair MySQL tables from the command line?