importing selected symbols from module the from statement is used to load specific definitions within module into the current namespace the from statement is identical to import except that instead of creating name referring to the newly created module namespaceit places references to one or more of the objects defined in the module into the current namespacefrom spam import foo foo(spam foo(imports spam and puts 'fooin current namespace calls spam foo(nameerrorspam the from statement also accepts comma-separated list of object names for examplefrom spam import foobar if you have very long list of names to importthe names can be enclosed in parentheses this makes it easier to break the import statement across multiple lines here' an examplefrom spam import (foobarspamin additionthe as qualifier can be used to rename specific objects imported with from here' an examplefrom spam import spam as sp sp(the asterisk (*wildcard character can also be used to load all the definitions in moduleexcept those that start with an underscore here' an examplefrom spam import load all definitions into current namespace the from module import statement may only be used at the top level of module in particularit is illegal to use this form of import inside function bodies due to the way in which it interacts with function scoping rules ( when functions are compiled into internal bytecodeall of the symbols used within the function need to be fully specifiedmodules can more precisely control the set of names imported by from module import by defining the list _all_ here' an examplemodulespam py _all_ 'bar''spamnames will export with from spam import importing definitions with the from form of import does not change their scoping rules for exampleconsider this codefrom spam import foo foo(prints " ' foo and is in this examplethe definition of foo(in spam py refers to global variable when reference to foo is placed into different namespaceit doesn' change the binding rules for variables within that function thusthe global namespace for function is always the module in which the function was definednot the namespace into which function is imported and called this also applies to function calls for examplein the lib fl ff