Python 如何引用当前包以与importlib.resources一起使用?

Python 如何引用当前包以与importlib.resources一起使用?,python,python-importlib,Python,Python Importlib,我已经安装了一个包(通常位于../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_b

我已经安装了一个包(通常位于
../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')
此\u包应使用什么?当我尝试相对自引用时,我得到了错误

TypeError: the 'package' argument is required to perform a relative import for '.'

令人尴尬的简单答案是:

this_package = __package__

txt = importlib.resources.read_text(__package__, 'a.txt')
img = importlib.resources.read_binary(__package__, 'b.png')