Python has a way to put definitions in a file and use them in the future.
The python file name is the module name. Within a module, you can access the module by variable
__name__
.
For example, define fibo.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
In another module or interpreter
1 2 3 4 |
|
Import
Importing module will place imported module names in his global symbol table.
Use import
statement to import a module
1 2 |
|
or
1 2 |
|
Python will not import names begining with underscore
_
.
Standard Modules
The dir() Function
Find out which names a modules defines.
1 2 |
|
Can also find the names you defines
1
|
|
By default, dir() cannot list built-in functions and variables. You need to specify it
1 2 |
|