Search code examples
pythonrhythmbox

Reading a file from Rhythmbox plugin


In my plugin for Rhythmbox I need to read data from xml file. The xml file is the same as the script. I read the file like this :

from xml.dom.minidom import parse    
doc = parse('sites.xml')

I get an error saying that the file is not found. I figured out that the script look in home folder not in the /usr/lib/rhythmbox/plugins/myfoder/. Is it an error of my script or just a limit of Rhythmbox?

Thanks.


Solution

  • Try to add direct address.

    import os
    from xml.dom.minidom import parse    
    BASE_DIR = os.path.dirname(os.path.abspath(__file__))
    xmlfile = os.path.join(BASE_DIR,'sites.xml')
    doc = parse(xmlfile)