15 lines
766 B
Python
15 lines
766 B
Python
import pkgutil
|
||
import os.path
|
||
__path__ = [
|
||
os.path.abspath(path)
|
||
for path in pkgutil.extend_path(__path__, __name__)
|
||
]
|
||
#import pkgutil: 导入 Python 的标准库模块 pkgutil,用于处理包。
|
||
# import os.path: 导入 os.path 模块,用于处理文件路径。
|
||
# 路径扩展:
|
||
|
||
# pkgutil.extend_path(__path__, __name__): 这个方法会根据当前模块的 __path__ 和模块名称 (__name__) 扩展出更多的路径。这些路径通常是指向包内的其他文件或子目录。
|
||
# 转换为绝对路径:
|
||
|
||
# 使用列表推导式遍历 pkgutil.extend_path(__path__, __name__) 返回的所有路径,并通过 os.path.abspath(path) 转换为绝对路径。
|
||
# 最终结果被赋值给 __path__,这将覆盖原有的 __path__ 值。 |