Skip to main content

Ability to fetch resources similar to Java Class.getResource()

Project description

Local Resources

This project is easy attempt to emulate Java's Class.getResource() method.

It provides simple access to files that are 'reachable' from directories and/or zip files referenced in PYTHONPATH.

Usage

Example:

from local_resources import Resource

with Resource("VERSION") as f:
    version = f.read()

It returns read-only file object in binary mode.

Aside of reading knowing files it provides 'list' method which is similar to os.listdir(path) with one caveat - directories are always returned with '/' appended:

from local_resources import Resource

files_and_dirs = Resource("").list()

for f in files_and_dirs:
    if f.endswith("myfiles/to_print_on_screen"):
        print(f"Do something with path {f}")
    else:
        with Resource(f) as file:
            print(f"File {f}:")
            print(file.read().decode('utf-8'))

Note: when list()' method is called there are no resources held after it finished, so there is no need for with` statement, nor cleaning up/closing resources at the end.

Note: for root of PYTHONPATH directories use """ or "/": Resource("").list().

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

local_resources-0.0.1.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

local_resources-0.0.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file local_resources-0.0.1.tar.gz.

File metadata

  • Download URL: local_resources-0.0.1.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.1

File hashes

Hashes for local_resources-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7f1626e6a692c4ce044d868cb00d1b8c5999dac0d8385215c183b58b68063a08
MD5 293fbafe58e79820704c3165c26cb528
BLAKE2b-256 ed44d4c6e9ce64a939c860efb8f2b9c57dea45522fff40c5ca2fe1849b20b9b9

See more details on using hashes here.

File details

Details for the file local_resources-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: local_resources-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.1

File hashes

Hashes for local_resources-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5b6eb3e153d95109219b5de7991ddfa92cf01aec5776bedbea17bd4aa26188c8
MD5 9f3eaa36df49ce6670d0fb6697f7f789
BLAKE2b-256 d2ae2be9c34d66fd8866f403980b8a0c1d9ea80f9f444fdc0c71521911d0233b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page