#coding=utf-8
#
# 模块
#
#读取模块文件
#10-1-1
#当前文件路径为 E:\py_code\
import sys
import test # 导入与当前文件同级目录文件
# 不能导入文件夹或文件夹路径+文件
# [警告] 文件夹名称 最好不要与 文件名称 相同
print test.myStr
#10-1-2 不同级目录
sys.path.append('E:\py_code\order') #导入绝对路径
import test2 #再导入文件
print test2.myStr
reload(test) # 重新导入文件
test.show()
#from order import test2
print __name__
print test.__name__
#获取路径搜索
import sys, pprint
pprint.pprint(sys.path)
#10-2包
#文件夹 是包
##########################################
# 导入文件夹,该文件夹 #
# 下必须包含 【__init__.py文件】, #
# 才可以使用 #
##########################################
import Dtest
import Dtest.test3 # 【文件夹名.文件名】作为模块变量
Dtest.test3.show() # 调用 只能加 全部
##########################################
# 通过文件夹 导入 文件 #
##########################################
from Dtest import test3
test3.show()
#10-3
#dir 函数;
#查看这个模块下有多少函数
print [n for n in dir(Dtest) if not n.startswith('_')]
#__all__变量
import copy #系统文件
print copy.__all__
#help 帮助函数
help(copy.copy)
help(test3.show) #打印函数 和 说明
print test3.show.__doc__ #打印说明
print copy.__file__ #打印生成的文件名 路径
#test.py, test2.py, test3.py, test4.py, test5.py
def show(num = 1):
print num
class testClass():
def __init__(self):
self.nCount = 1
def SetCount(self, nCount):
self.nCount = nCount
def GetCount(self):
print self.nCount
myStr = 'thanks! you see me!!'