modulespackagesand distribution following codethe call to bar(results in call to spam foo()not the redefined foo(that appears in the previous code examplefrom spam import bar def foo()print(" ' different foo"bar(when bar calls foo()it calls spam foo()not the definition of foo(above another common confusion with the from form of import concerns the behavior of global variables for exampleconsider this codefrom spam import afoo foo(print(aimport global variable modify the variable prints " ' foo and is prints " hereit is important to understand that variable assignment in python is not storage operation that isthe assignment to in the earlier example is not storing new value in aoverwriting the previous value insteada new object containing the value is created and the name is made to refer to it at this pointa is no longer bound to the value in the imported module but to some other object because of this behaviorit is not possible to use the from statement in way that makes variables behave similarly as global variables or common blocks in languages such as or fortran if you want to have mutable global program parameters in your programput them in module and use the module name explicitly using the import statement (that isuse spam explicitlyexecution as the main program there are two ways in which python source file can execute the import statement executes code in its own namespace as library module howevercode might also execute as the main program or script this occurs when you supply the program as the script name to the interpreterpython spam py each module defines variable_ _name_ _that contains the module name programs can examine this variable to determine the module in which they're executing the top-level module of the interpreter is named _main_ programs specified on the command line or entered interactively run inside the _main_ module sometimes program may alter its behaviordepending on whether it has been imported as module or is running in _main_ for examplea module may include some testing code that is executed if the module is used as the main program but which is not executed if the module is simply imported by another module this can be done as followscheck if running as program if _name_ =' _main_ 'yes statements elsenoi must have been imported as module statements it is common practice for source files intended for use as libraries to use this technique for including optional testing or example code for exampleif you're developing lib fl ff