Sunday, 15 February 2015

Load txt file from resources in Python -



Load txt file from resources in Python -

i have .qrc file:

<rcc> <qresource prefix="/files"> <file alias='icon'>../icons/delta.jpg</file> <file alias='eng'>../languages/english.txt</file> </qresource> </rcc>

which compile python python_rc.py file pyrcc4. in code have:

import qtgui, python_rc ... icon = qtgui.qicon() icon.addpixmap(qtgui.qpixmap(':/files/icon'), qtgui.qicon.normal, qtgui.qicon.off) self.setwindowicon(icon) ... text = codecs.open(':/files/eng', 'r', "utf-8")

...icon loaded no problems, txt file get:

ioerror: [errno 22] invalid mode ('rb') or filename: ':/files/eng'

so question is: how should load eng python_rc? possible text files or pictures?

you can seek this:

fd = qtcore.qfile(":/files/eng") if fd.open(qtcore.qiodevice.readonly | qtcore.qfile.text): text = qtcore.qtextstream(fd).readall() fd.close()

because txt file in qt resourse file can't utilize this:

text = codecs.open(':/files/eng', 'r', "utf-8")

python file-io resources text-files

No comments:

Post a Comment