Skip to content

Glossary: Refactoring and Clean Code

__name__ guard

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

An `if __name__ == "__main__":` line that makes code run only when the file is run directly, not when another file imports it. It makes a script safe to import in tests.

Where the book teaches it

Related terms

SeamLegacy code