Python Language Importing modules

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • import module_name
  • import module_name.submodule_name
  • from module_name import *
  • from module_name import submodule_name [, class_name, function_name, ...etc]
  • from module_name import some_name as new_name
  • from module_name.submodule_name import class_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.



Got any Python Language Question?