'''
容器是对数据的封装
函数是对语句的封装
类是对方法和属性的封装
模块就是一个程序文件
新建一个.py文件,名为 hello
其内容如下:
def hi():
print('hello')
它其实就是一个模块,可以进行调用,但记得程序文件都要放到同一文件夹下
'''
import hello
hello.hi()
from hello import hi
hi()
import hello as n
n.hi()
'''
新建一个.py文件,名为 hello
其内容如下:
def hi():
print('hello')
def test():
print('测试成功')
test()
在单独执行模块文件时,有时需要测试(这里的text()),但是调用模块时,测试代码会执行
'''
import hello as n
n.hi()
'''
输出:
测试成功
hello
'''
'''
为了避免这种情况,修改模块如下:
其内容如下:
def hi():
print('hello')
def test():
print('测试成功')
if __name__='__main__':
test()
'''
import hello as n
n.hi()
import sys
print(sys.path)
sys.path.append('==文件路径名==(比如:E:\\python\\Lib\\test)')
'''
包是一个文件夹,包含了很多模块,python规定包中必须新建一个名为:__init__.py 的文件
包中模块的导入:
import 包名.模块名 as 新名字