Thanks to visit codestin.com
Credit goes to github.com

Skip to content

`dir1/file.txt' must be only a file name #104

Closed
@jaraco

Description

@jaraco

In GitLab by @omry3 on Jun 24, 2020, 22:59

From https://importlib-resources.readthedocs.io/en/latest/:
"In our terminology, a resource is a file tree that is located within an importable Python package."

Because this is talking about a file tree, I would expect to be able to check for resources in sub directories inside the importable Python package.
This does not seem to be the case.
The example below has two issues I am wondering about:

  1. How do I check if a directory exists?
  2. Why the error dir1/file.txt' must be only a file name? it seems that this should be supported based on the project terminology.

Source tree: test-importlib.zip

Structure:

$ tree
.
├── package
│   ├── dir1
│   │   └── file.txt
│   ├── file.txt
│   └── __init__.py
└── test.py

Output:

$ python test.py 
is_resource("package", "file.txt") True
is_resource("package", "dir1") False , how do I check if a directory exists?
is_resource("package", "dir1/file.txt") failed with dir1/file.txt' must be only a file name'
is_resource("package.dir1", "file.txt") False need an __init__.py in dir1

Thanks.

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