Jun-19-2024, 09:42 PM
(This post was last modified: Jun-19-2024, 09:42 PM by Gribouillis.)
(Jun-14-2024, 01:18 AM)Skaperen Wrote: is there any circumstance in which inserting code, such as while editing, has a different result than doing an import of the same code@rodiongork 's answer is excellent. When you import a module, this module's code is executed in the new module's namespace. When you insert code, it is executed in the namespace of the module where the code is inserted.
This can have unpredictable consequences. Variables can be shadowed (this also includes functions and classes), code depending on the module name could behave differently, for example
if __name__ == '__main__'
code, etc.
« We can solve any problem by introducing an extra level of indirection »