Congratulations! You now know how to create Python main()
functions.
Here’s what you covered:
-
Knowing the value of the
__name__
variable is important to write code that serves the dual purpose of executable script and importable module. -
__name__
takes on different values depending on how you executed your Python file.__name__
will be equal to:"__main__"
when the file is executed from the command line or withpython -m
(to execute a package’s__main__.py
file)- The name of the module, if the module is being imported
- Python programmers have developed a set of best practices to use when you want to develop reusable code.
To learn more about the concepts covered in this course, check out What Does if name == “main” Do in Python?.
Now you’re ready to go write some awesome Python main()
function code!
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
Gregory Klassen on March 10, 2020
What does it mean to … ” or with python -m (to execute a package’s main.py file)