1.创建 loadlib.py and mylib.py
2. import mylib #调用mylib.py
方法:
1. mylib.py
<pre style="font-family: 'Source Code Pro'; font-size: 11.3pt; background-color: rgb(255, 255, 255);"><span style="color:#808080;"><em>#-*-coding:utf-8-*-
</em></span>__author__ = <span style="color:#008000;"><strong>'allen'
</strong></span><span style="color:#008000;"><strong>
</strong></span><span style="color:#000080;"><strong>class </strong></span>Hello:
<span style="color:#000080;"><strong>def </strong></span>sayHello(<span style="color:#94558d;">self</span>):
<span style="color:#000080;"><strong>print</strong></span>(<span style="color:#008000;"><strong>"Hello World"</strong></span>)
2. import mylib
#-*-coding:utf-8-*- __author__ = 'allen' # import mylib # # h = mylib.Hello() # h.sayHello() from mylib import Hello #直接导入hello类,更加方便的调用
h = Hello() h.sayHello()