Skip to main content
Loading page…
Python Mastery
Chapter 7
Lesson 2 of 4
Writing Your Own Modules
Contents
Notes
Tutor
Concept
Creating Your First Module
Loading activity…
Previous
1 / 8
Continue
Contents
Notes
Discussion
Tutor
20 min
8 activities
0 of 8 done
In this lesson
1
Creating Your First Module
2
Module-Level Code Runs at Import Time
3
The __name__ Guard
4
A Complete Module with __name__ Guard
5
What Does __name__ Equal?
6
Build a Math Utilities Module
7
Convention: Leading Underscore = Private
8
Explain the __name__ Guard in Your Own Words
Objectives
Create a Python module with reusable functions and import it from another file
Use the `if __name__ == '__main__'` guard to separate library code from script code
Write module-level docstrings and understand how they appear via help()
Explain what happens to module-level code at import time
Chapter 7 · Modules, Packages & Imports
The Import System
Writing Your Own Modules
Packages & Project Layout
pip, PyPI & Dependencies
Previous: The Import System
Next: Packages & Project Layout