Last active
December 25, 2015 20:29
-
-
Save jimbaker/7035646 to your computer and use it in GitHub Desktop.
Using pkg_resources for data files packaged into a singlejar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from java.io import BufferedInputStream as BIS | |
>>> import pkg_resources | |
>>> bis = BIS(pkg_resources.resource_stream("clamped", "data/example.txt")) | |
TypeError: java.io.BufferedInputStream(): 1st arg can't be coerced to java.io.InputStream | |
>>> f = pkg_resources.resource_stream("clamped", "data/example.txt") | |
>>> f.read() | |
'Some example text\n' | |
>>> path = pkg_resources.resource_filename("clamped", "data/example.txt") | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
File "/Users/jbaker/opensource/clamped/clamped-0.1-single.jar/Lib/pkg_resources$py.class", line 944, in resource_filename | |
File "/Users/jbaker/opensource/clamped/clamped-0.1-single.jar/Lib/pkg_resources$py.class", line 1625, in get_resource_filename | |
NotImplementedError: resource_filename() only supported for .egg, not .zip | |
>>> pkg_resources.resource_string("clamped", "data/example.txt") | |
'Some example text\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment