新建模块,导入模块的方法

新建模块:

注意类的定义中函数声明一定要包含 self 参数

# -*- coding: utf-8 -*-
class module1:
    def __init__(self):
        print(self)

    def function1(self):
        print(self)

    def function2(self):
        print(self)

 

要当模块调用的py文件一般是保存在系统目录:

…\Lib\site-packages

当然也可以保存在其他位置,例如:

C:\WinPython-32bit-3.4.4.2\my_WorkSpace1\module1.py

导入模块:

 

# -*- coding: utf-8 -*-
import sys
sys.path.append('C:\WinPython-32bit-3.4.4.2\my_WorkSpace1\module1.py')
import module1
module1.module1.function1('调用模块成功!')

 

效果:

360截图20160522212923400

posted @ 2016-05-22 21:15  佩雷尔曼的信徒  阅读(168)  评论(0编辑  收藏  举报