Python基础之如何使用其他包的模块内容? 1、如何使用其他包的模块的内容呢方式一import 包名提示 import后面是什么就直接用什么 1import后面是包名那么就用包名.模块名.xx 2import后面是模块名那么就用模块名.xx 3import后面是模块中的成员那么就用 xx不需要再加包名.模块名. 注意对于方式一来说 import 包名 只是让python解释器找到包了但是它仍然找不到包中的模块 我们需要在该包的__init__.py文件中加一句 from . import 模块名 这里的.代表的是在当前包目录下搜索xx模块名#使用mygraphic包的circle.py模块的area等函数importmygraphicprint(圆面积,mygraphic.circle.area(2.5))print(矩形面积,mygraphic.rectangle.area(8,6))# #默认情况下搜索模块的顺序没有包含包目录# import sys# print(sys.path)方式二import 包名.模块名 [as 别名] from 包名 import 模块名 [as 别名]#使用mygraphic包的circle.py模块的area等函数frommygraphicimportcircleprint(圆面积,circle.area(2.5))importmygraphic.rectangleprint(矩形面积,mygraphic.rectangle.area(6,2))方式三from 包名.模块名 import 成员名 [as 别名]# 使用mygraphic包的circle.py模块的area等函数frommygraphic.circleimportareaascafrommygraphic.rectangleimportareaasraprint(圆面积,ca(2.5))print(矩形面积,ra(7,2))方式四from 包名.模块名 import *# 使用mygraphic包的circle.py模块的area等函数frommygraphic.circleimport*frommygraphic.rectangleimportareaasraprint(圆面积,area(2.5))print(矩形面积,ra(7,2))方式五from 包名 import *(1)需要在被导入的包的__init__.py文件中加 from . import 模块名 (2)或者在被导入的包的__init__.py文件中加 __all__ [模块名,模块名]frommygraphicimport*print(圆面积,circle.area(2.5))frommygraphicimport*print(圆面积,circle.area(2.5))