一孝凌、自定義模塊
定義模塊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()