Loading topic
import. It explains what Python does when it runs an import statement, and why a second import of the same module does almost nothing.2 min readpython file.py from a terminal, and know that import runs a file once and caches it in sys.modules.2 min readimport does and that imported modules are cached in sys.modules. Here you will learn where Python looks when a module is not yet in that cache.2 min readsys.path is searched. Here we move from one file to a directory of files.2 min readimport and from ... import bind names, and that you have seen a package as a directory with an __init__.py file. It uses the shapes package from the previous chapter.2 min readsys.path is searched, and how a package with __init__.py is laid out. Inside a package, you can name another module in two ways: by its full path from a top-level package, or by its position relative to the current module.2 min read__init__.py and submodules, and that you know relative imports. Here you decide which names a package exposes and which stay internal.2 min readsys.path is, and how a package with __init__.py is laid out. It builds on the __main__ guard and relative imports covered earlier.2 min read__init__.py files and know how sys.path is searched. It covers where to put a package in a project and how to make it importable from anywhere.2 min readimport executes a module once and caches it in sys.modules, and that you can read relative and absolute imports inside a package.2 min readimport binds names, how sys.modules caches modules, and how sys.path is searched. Two mistakes cause many confusing import errors: giving your own file the name of another module, and running too much code when a module loads.2 min readsys.modules cache and the sys.path search list from earlier chapters. Here you will see the machinery that uses both.2 min read__init__.py, how sys.path is searched, and how absolute imports work.2 min readimport runs a module once and caches it in sys.modules, and how sys.path decides where Python looks. Here you will import modules whose names are only known at run time, load a file from an arbitrary path, and re-run a module you have already imported.2 min read