Python中包的导入

导入形式 代码样例 调用方式 调用方式
import 包名.模块名 import utils.my_fun 包名.模块名.功能名 utils.my_fun.fun1()
from 包名 import 模块名 from utils import my_fun 模块名.功能名 my_fun.fun1()
from 包名 import * from utils import * 模块名.功能名 my_fun.fun1()
from 包名.模块名 import 功能名 from utils.my_fun import fun1  功能名 fun1()
from 包名.模块名 import * from utils.my_fun import * 功能名 fun1()

from 包名 import *时,必须在包内的__init__.py中定义__all__=["模块1","模块2"]

posted on 2026-06-03 21:58  ymworkroom  阅读(4)  评论(0)    收藏  举报