import 模块
- import 试图导入模块时 首先导入当前路径下的相同名字的模块
sendmsg.py
def test1():
print("sendmsg test1")
def test2():
print("sendmsg test")
receive.py
def test1():
print("receive test1")
def test2():
print("receive test2")
main.py
#方法1
#import sendmsg
#sendmsg.test1
#sendmsg.test2
#方法2
from sendmsg import test1, test2
test1()
test2()
#方法三
from sendmsg import *
from recive import * '''如果recive有相同的方法test1 那么后面一个(recive中的test1)将顶替前面的方法'''
test1()
test2()
import 重定义 模块名
- import this_is_a _lang_name as td #将这个很长的模块名重定义为td 类似C语言中的 typedef