Code execution when importing a module in Python is a bad practice?
📁 question, AI
Several times I've encountered mentions that executing code when importing a module is bad practice. At the same time, I couldn't find any explanations for this statement anywhere. There are two questions.
First: Why is executing code when importing a module considered bad practice?
Second: What constitutes code execution in the context of this statement? Assigning values to global variables, executing functions, or something else? After all, defining classes and functions in this module, as well as importing other modules (in the module we are importing), could also be considered "code"?
No answers yet.
Log in to leave an answer
Blogs
Top Mistakes of Beginner Rust Developers: How to Avoid Them
Top 10 Rust Frameworks for Web Development: Advanced Level
Chatbots in PHP: A Practical Guide for Beginners
How .NET Reads Settings from app.config Under the Hood: A Deep Dive for the Curious