With the -c
(command) argument (assuming your file is named foo.py
):
$ python -c 'import foo; print foo.hello()'
Alternatively, if you don’t care about namespace pollution:
$ python -c 'from foo import *; print hello()'
And the middle ground:
$ python -c 'from foo import hello; print hello()'
Related Contents:
- Why does my recursive function return None?
- Creating functions in a loop
- What causes my function to return None at the end?
- Passing a dictionary to a function as keyword parameters
- Apply function to each element of a list
- Python not working in the command line of git bash
- Passing functions with arguments to another function in Python?
- Executing multi-line statements in the one-line command-line
- How can I find the number of arguments of a Python function?
- Is there an easy way to pickle a python function (or otherwise serialize its code)?
- How to send an email with Python?
- Using a dictionary to select function to execute
- How to call function that takes an argument in a Django template?
- How are Python in-place operator functions different than the standard operator functions?
- Calling a function upon button press
- Is it possible to run function in a subprocess without threading or writing a separate file/script.
- How to get current function into a variable?
- How to Open a file through python
- Calling functions from a Tkinter Frame to another
- Linux command-line call not returning what it should from os.system?
- How do I define a function with optional arguments?
- What are good uses for Python3’s “Function Annotations”?
- Python: return the index of the first element of a list which makes a passed function true
- Why is “None” printed after my function’s output?
- Why do some functions have underscores “__” before and after the function name?
- How do I make a python script executable?
- I have a string whose content is a function name, how to refer to the corresponding function in Python?
- Value error trying to install Python for Windows extensions
- How can I use `return` to get back multiple values from a loop? Can I put them in a list?
- Basic explanation of python functions
- Why am I getting a NameError when I try to call my function?
- Do something every x (milli)seconds in pygame
- Python, installing clarifai –> VS14.0 link.exe failed with exit status 1158
- How to pass dictionary items as function arguments in python? [duplicate]
- How to execute a function asynchronously every 60 seconds in Python?
- Is it possible to not return anything from a function in python? (What happens if the function reaches the end without `return`ing?)
- What is first class function in Python
- Is it possible to change a function’s default parameters in Python?
- python: how to get information about a function?
- How to make a python, command-line program autocomplete arbitrary things NOT interpreter
- Python Turtle.Terminator even after using exitonclick()
- Is there a function in python to split a word into a list? [duplicate]
- Get a list/tuple/dict of the arguments passed to a function?
- Launch Pycharm from command line (terminal)
- Python functions with multiple parameter brackets
- Check if two Python functions are equal
- How to run a python script from IDLE interactive shell?
- How do nested functions work in Python?
- Reverse a string without using reversed() or [::-1]?
- Why doesn’t an import in an exec in a function work?