Importing modules
suggest changeSyntax
importmodule_nameimportmodule_name.submodule_namefrommodule_nameimport *frommodule_nameimportsubmodule_name[,class_name,function_name, …etc]frommodule_nameimportsome_nameasnew_namefrommodule_name.submodule_nameimportclass_name[,function_name, …etc]
Remarks
Importing a module will make Python evaluate all top-level code in this module so it learns all the functions, classes, and variables that the module contains. When you want a module of yours to be imported somewhere else, be careful with your top-level code, and encapsulate it into if __name__ == '__main__': if you don’t want it to be executed when the module gets imported.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents