Python equivalent to Java's Class.getResource
Question: 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](http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Class.html#getResource%28java.lang.String%29)
method, and I'm wondering if something similar exists in Python.


Answer: Take a look at
[pkg_resources](http://packages.python.org/distribute/pkg_resources.html#resourcemanager-
api), 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:

    
    
    import pkg_resources
    my_data = pkg_resources.resource_string(__name__, "foo.dat")
    

