6. Modules — Python 3.16.0a0 documentation

docs.python.org

Tin mới

6.3. The dir() Function¶

The built-in function dir() is used to find out which names a module defines. It returns a sorted list of strings:

5. Data Structures

7. Input and Output

Python Module Index

3.16.0a0 Documentation

The Python Tutorial

6.1. More on Modules¶

To support this, Python has a way to put definitions in a file and use them in a script or in an interactive instance of the interpreter. Such a file is called a module; definitions from a module can be imported into oth

Python Scopes and Namespaces

To support this, Python has a way to put definitions in a file and use them in a script or in an interactive instance of the interpreter. Such a file is called a module; definitions from a module can be imported into oth

6.1. More on Modules¶

A module can contain executable statements as well as function definitions. These statements are intended to initialize the module. They are executed only the first time the module name is encountered in an import statem

importlib.reload()

For efficiency reasons, each module is only imported once per interpreter session. Therefore, if you change your modules, you must restart the interpreter – or, if it’s just one module you want to test interactively, use

sys.builtin_module_names

When a module named spam is imported, the interpreter first searches for a built-in module with that name. These module names are listed in sys.builtin_module_names. If not found, it then searches for a file named spam.p

site: Module responsible for site-specific configuration.

The installation-dependent default (by convention including a site-packages directory, handled by the site module).

The initialization of the sys.path module search path

When a module named spam is imported, the interpreter first searches for a built-in module with that name. These module names are listed in sys.builtin_module_names. If not found, it then searches for a file named spam.p

compileall: Tools for byte-compiling all Python source files in a directory tree.

The module compileall can create .pyc files for all modules in a directory.

winreg: Routines and objects for manipulating the Windows registry.

These two variables are only defined if the interpreter is in interactive mode.

6.2. Standard Modules¶

These two variables are only defined if the interpreter is in interactive mode.

builtins: The module that provides the built-in namespace.

The built-in function dir() is used to find out which names a module defines. It returns a sorted list of strings: