Tag

__name__

0 views collected around this technical thread.

IT Services Circle
IT Services Circle
Jan 14, 2025 · Fundamentals

Understanding the __name__ Variable and the if __name__ == '__main__' Guard in Python

This article explains how Python's __name__ variable works, why the if __name__ == '__main__' construct is used to differentiate direct script execution from module import, and shows practical examples including simple scripts and multiprocessing scenarios.

Python__name__if __name__ == '__main__'
0 likes · 5 min read
Understanding the __name__ Variable and the if __name__ == '__main__' Guard in Python
Test Development Learning Exchange
Test Development Learning Exchange
Jun 11, 2024 · Fundamentals

Deep Understanding of __main__ and __name__ in Python

This article explains the special built‑in identifiers __main__ and __name__ in Python, describing how they indicate a module's execution context, how to use them to separate script and library code, and provides multiple practical code examples.

Module__name__code
0 likes · 6 min read
Deep Understanding of __main__ and __name__ in Python
IT Services Circle
IT Services Circle
May 29, 2024 · Fundamentals

Understanding the __name__ Variable in Python Scripts

This article explains how the __name__ variable is set when running Python scripts directly or importing them, demonstrates its behavior with multiple .py files, shows how unintended code can be executed, and introduces the if __name__ == '__main__' guard to control execution.

@ImportPython__name__
0 likes · 6 min read
Understanding the __name__ Variable in Python Scripts
Python Programming Learning Circle
Python Programming Learning Circle
Jun 28, 2021 · Fundamentals

Understanding Python's __name__ Variable: Purpose, Values, and Practical Examples

This article explains the built‑in __name__ variable in Python, how its value differs when a script is run directly versus imported as a module, and demonstrates both scenarios with clear code examples and visual diagrams.

@ImportModulePython
0 likes · 5 min read
Understanding Python's __name__ Variable: Purpose, Values, and Practical Examples
Python Programming Learning Circle
Python Programming Learning Circle
Apr 19, 2021 · Fundamentals

Understanding the main() Function and Execution Modes in Python

This article explains Python's lack of a built‑in main() entry point, introduces the conventional main() pattern using the __name__ == '__main__' guard, compares command‑line and import execution modes, and provides best‑practice guidelines for structuring Python scripts and modules.

Best PracticesPython__name__
0 likes · 8 min read
Understanding the main() Function and Execution Modes in Python