I have some XML files on my PYTHONPATH that I would like to load using their path on the PYTHONPATH, rather than their (relative or absolute) path on the filesystem. I could simply inline them as strings in a Python module (yay multiline string literals), and then load them using a regular import statement, but I’d like to keep them separated out as regular XML files, if possible. In Java world, the solution to this would be to use the Class.getResource method, and I’m wondering if something similar exists in Python.
I have some XML files on my PYTHONPATH that I would like to load
Share
Take a look at pkg_resources, it includes apis for the inclusion to generic resources. It is thought to work with python eggs and so it could be much more of you need.
Just an example taken from the doc: