Skip to content

Add example of using importlib.resources.files() in Python 3.12 #6

@winstontsai

Description

@winstontsai

This was a helpful example repo. I just have one request.

In Python 3.12 they updated importlib.resources.files(): https://docs.python.org/3/library/importlib.resources.html#importlib.resources.files

Changed in version 3.12: package parameter was renamed to anchor. anchor can now be a non-package module and if omitted will default to the caller’s module. package is still accepted for compatibility but will raise a DeprecationWarning. Consider passing the anchor positionally or using importlib_resources >= 5.10 for a compatible interface on older Pythons.

Could you include an example of omitting anchor so that it defaults to the caller’s module (or explicitly passing the module name with a string literal or __name__? I tried myself and while it works before packaging with zipapp, it fails to open and read the data file when running the zip. I'm not sure if I'm doing something wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions