
Second, it does not check the cache if there is no Recompiles and does not store the result for the module that’s loaded directlyįrom the command line. Python does not check the cache in two circumstances. Same library can be shared among systems with different architectures. Also, the compiled modules are platform-independent, so the To see if it’s out of date and needs to be recompiled. Python checks the modification date of the source against the compiled version Naming convention allows compiled modules from different releases and different Version of spam.py would be cached as _pycache_/. For example, in CPython release 3.3 the compiled Where the version encodes the format of the compiled file it generally contains In the _pycache_ directory under the name module.

To speed up loading modules, Python caches the compiled version of each module Module directly into the importing module’s symbol table. There is a variant of the import statement that imports names from a The imported module names are placed in the importing module’s global Import statements at the beginning of a module (or script, for that It is customary but not required to place all On the other hand, if you know what you areĭoing you can touch a module’s global variables with the same notation used to Use global variables in the module without worrying about accidental clashes Table by all functions defined in the module. (They are also run if the file is executed as a script.)Įach module has its own private symbol table, which is used as the global symbol The first time the module name is encountered in an import statement. These statements are intended to initialize the module. For instance, use your favorite text editor to create a fileĬalled fibo.py in the current directory with the following contents:Ī module can contain executable statements as well as function definitions. Module’s name (as a string) is available as the value of the global variable Script executed at the top level and in calculator mode).Ī module is a file containing Python definitions and statements. The main module (the collection of variables that you have access to in a

Module definitions from a module can be imported into other modules or into Script or in an interactive instance of the interpreter. To support this, Python has a way to put definitions in a file and use them in a Handy function that you’ve written in several programs without copying its Split it into several files for easier maintenance. As your program gets longer, you may want to Input for the interpreter and running it with that file as input instead. Somewhat longer program, you are better off using a text editor to prepare the Have made (functions and variables) are lost. If you quit from the Python interpreter and enter it again, the definitions you
