A Complete Beginner’s Introduction to Python
Part 10
Modules
Let’s create our own module! For this we’ll need to:
- Come up with some functionality we want to encapsulate into a function.
- Save that function and any
import
statements it requires in a new file that ends with.py
- Open up the Python interpreter and import that file by running
import filename
wherefilename
is the name of the file without the.py
on the end. - Run the function by entering in
filename.functioname()
and entering any parameters it requires!