Python Modules: Difference between revisions
Jump to navigation
Jump to search
Created page with '== Search Path == An <code>import</code> statement refers to python files without any path or extension information. To import <code>C:\work\test\my_test.py</code>, you would jus…' |
(No difference)
|
Latest revision as of 22:21, 1 February 2011
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