2019年5月2日 模块

模块

1.python 标准模块

2.第三分模块

3.应用程序自定义模块

import:
  1.执行文件
  2.引入变量名
  

bin.py

# import cal,time #把cal先执行一次

#from cal import add
#from cal import reduce

def add(x,y):
    return x+y+100

from my_module import cal  #从my_module中寻找到cal
from my_module import main #因为上面一句解释器已经认识了my_module路径
# from cal import * #不推荐,*代表全部
print(cal.add(3,5)) #上面又定义了个add,但是被from * 里面的程序中的add覆盖了
print(cal.reduce(2,5))

main.s()

main.py

from my_module import cal #不可以直接使用 import cal,因为程序只认一条路径,按照执行程序来寻找的
def s():
    print(cal.add(2,2))

cal.py

print('import导入时,cal中先执行一次 ok')

def add(x,y):
    return x+y

def reduce(x,y):
    return x-y

def chen(x,y):
    return x*y

def chu(x,y):
    return x/y

猜你喜欢

转载自www.cnblogs.com/python1988/p/10801713.html