piece of code are completely determined by the code' physical position in your file scopes are never influenced by function calls or module imports namespace nesting in some sensealthough imports do not nest namespaces upwardthey do nest downward that isalthough an imported module never has direct access to names in file that imports itusing attribute qualification paths it is possible to descend into arbitrarily nested modules and access their attributes for exampleconsider the next three files mod py defines single global name and attribute by assignmentx mod py in turn defines its own xthen imports mod and uses qualification to access the imported module' attributex import mod print(xend='print(mod xmy global mod ' mod py also defines its own xthen imports mod and fetches attributes in both the first and second filesx import mod print(xend='print(mod xend='print(mod mod xmy global mod ' nested mod ' reallywhen mod imports mod hereit sets up two-level namespace nesting by using the path of names mod mod xit can descend into mod which is nested in the imported mod the net effect is that mod can see the xs in all three filesand hence has access to all three global scopespython mod py the reversehoweveris not truemod cannot see names in mod and mod cannot see names in mod this example may be easier to grasp if you don' think in terms of namespaces and scopesbut instead focus on the objects involved within mod mod is just name that refers to an object with attributessome of which may refer to other some languages act differently and provide for dynamic scopingwhere scopes really may depend on runtime calls this tends to make code trickierthoughbecause the meaning of variable can differ over time in pythonscopes more simply correspond to the text of your program module namespaces