(identifier, pkgname=__name__)
return open(os.path.normpath(path), 'rb')
Acquire a readable object for a given package name and identifier.
    An IOError will be raised if the resource can not be found.

    For example::

        mydata = get_esource('mypkgdata.jpg').read()

    Note that the package name must be fully qualified, if given, such
    that it would be found in sys.modules.

    In some cases, getResource will return a real file object.  In that
    case, it may be useful to use its name attribute to get the path
    rather than use it as a file-like object.  For example, you may
    be handing data off to a C API.
Acquire a readable object for a given package name and identifier.
    An IOError will be raised if the resource can not be found.
Acquire a readable object for a given package name and identifier . An IOError will be raised if the resource can not be found .
def get_resource(identifier, pkgname=__name__):
    """
    Acquire a readable object for a given package name and identifier.
    An IOError will be raised if the resource can not be found.

    For example::

        mydata = get_esource('mypkgdata.jpg').read()

    Note that the package name must be fully qualified, if given, such
    that it would be found in sys.modules.

    In some cases, getResource will return a real file object.  In that
    case, it may be useful to use its name attribute to get the path
    rather than use it as a file-like object.  For example, you may
    be handing data off to a C API.
    """

    mod = sys.modules[pkgname]
    fn = getattr(mod, '__file__', None)
    if fn is None:
        raise IOError("%r has no __file__!")
    path = os.path.join(os.path.dirname(fn), identifier)
    loader = getattr(mod, '__loader__', None)
    if loader is not None:
        try:
            data = loader.get_data(path)
        except (IOError,AttributeError):
            pass
        else:
            return StringIO(data)
    return open(os.path.normpath(path), 'rb')
def get_resource ( identifier , pkgname = __name__ ) : mod = sys . modules [ pkgname ] fn = getattr ( mod , '__file__' , None ) if fn is None : raise IOError ( "%r has no __file__!" ) path = os . path . join ( os . path . dirname ( fn ) , identifier ) loader = getattr ( mod , '__loader__' , None ) if loader is not None : try : data = loader . get_data ( path ) except ( IOError , AttributeError ) : pass else : return StringIO ( data ) return open ( os . path . normpath ( path ) , 'rb' )