【发布时间】:2019-11-15 19:23:24
【问题描述】:
我有一个安装包(通常位于…/lib/pythonX.Y/site-packages/my-package 内),其中包含(除其他外)资源…/my-package/a.txt 和…/my-package/b.png。我想使用以下代码从…/my-package/get_my_resources.py 访问这些资源:
txt = importlib.resources.read_text(this_package, 'a.txt')
img = importlib.resources.read_binary(this_package, 'b.png')
this_package 应该使用什么?当我尝试相对自引用this_package = '.' 时,我得到了错误
TypeError: the 'package' argument is required to perform a relative import for '.'
【问题讨论】: