Python Modules
Search Path
An import
statement refers to python files without any path or extension information. To import C:\work\test\my_test.py
, you would just type
import my_test
The interpreter searches in the following locations:
- The current directory.
- The PYTHONPATH variable.
- The standard library
Importing
import time
x = time.localtime()
from time import localtime
x = localtime()
from time import *
x = localtime()
Test Code
Everything in a module file gets executed when the module is first imported. Test code should run only when you explicitly run the module file itself.
if __name__ == '__main__':
# run test code