Уровень 0 · материалов: 3
В кластер входят документы об архитектуре Python-пакетов, организации импортов и управлении точками запуска кода.
Общие признаки: структура модулей Python, импорт кода, точки входа в программу, управление исполнением скриптов
Группа выше: Окружение, зависимости и структура проекта
Смысл: The main idea is to explain how the '__name__' variable allows a Python script to distinguish whether it is being executed directly or imported as a module, thereby preventing unwanted code execution during imports.
The article explains that 'if __name__ == "__main__"' is used in Python to ensure specific code only runs when the file is executed directly, not when it is imported by another script.
Смысл: The main idea is to teach beginners how to organize Python code using imports, while highlighting the architectural difference between absolute and relative imports and warning about the Singleton nature of Python modules.
A beginner-friendly guide to Python's import mechanisms, covering syntax, the Singleton nature of modules, and the trade-offs between absolute and relative imports.
Смысл: The main idea is that using a __main__.py file in a Python package is a superior way to define the entry point for command-line execution compared to using standalone scripts like run.py.
Instead of using ambiguous entry scripts, use a __main__.py file to allow your Python package to be executed cleanly via the 'python -m' command.