Python (Scripting) - Calling functions from another Python script

by
Jeremy Canfield |
Updated: November 06 2023
| Python (Scripting) articles
Often, shared functions are created in a "master" Python script, so that "child" Python scripts can use the shared functions.
Let's say functions.py contains the following.
#!/usr/bin/python
def Hello(greeting):
return greeting
Here is how you could call functions.py from another Python script, such as testing.py. In this example, every function in functions.py will be made available in the testing.py script.
#!/usr/bin/python
from functions import *
result = Hello("Hello World")
print(result)
Or, if you want to limit the scope of the functions being imported, you can import specific functions.
#!/usr/bin/python
from functions import Hello
result = Hello("Hello World")
print(result)
Did you find this article helpful?
If so, consider buying me a coffee over at