一、自定义模块
定义模块module.py
def test(a,b):
return a+b
def test2(a,b):
pass
- 引用模块
import module
print module.test(1,2)
- 引用模块后可直接使用方法
from m import test2
print test2(1,2)
二、导入系统模块
import sys.path
from os import *
import string, re
import time, random
import socket, threading
三、导入私有模块
import sys
# /home/m.py
path = '/home/'
# 把模块添加到path 中
sys.path.append(path)
from m import test2
test2()