自定义可导入类
自写类及内部导入(pv.py
)
class test:
b = 2
def __init__(self):
self.c = 3
def printme(self):
print("hello")
a = 1
# 内部导入演示
if __name__ == "__main__":#外部导入时,不执行该部分
import pv
TEST = test()
print(pv.a,a,TEST.b,TEST.c)
TEST.printme()
外部导入类(test.py
)
import pv
from pv import a
test = pv.test()
print(pv.a,a,test.b,test.c)
test.printme()