Skip to content

Glossary: Python Beyond the Basics

__name__ guard

Also written: if __name__ == "__main__", __name__, __main__

An `if __name__ == "__main__":` check that runs code only when a file is run directly, not when another file imports it. It stops test lines in pricing.py from running on import, and usually calls `main()`.

Where the book teaches it

Related terms

modulepackage