Active Topics

 


Reply
Thread Tools
Posts: 127 | Thanked: 54 times | Joined on Nov 2009
#1
Hi,

I've been following the excellent guide of how to create apps with python / Qt. I've got an issue which I hope somebody can resolve. I have a python app that gets tube details etc - and I'm trying to give it a nice front end.

When I try to assign a dictionary value I get the following error:

Code:
for Station in TubeStationList[self.ui.listTubeLine.currentItem().text()].values():

KeyError: PyQt4.QtCore.QString(u'metropolitan')
So the value should be 'metrolpolitan' that's correct. What's the issue with syntax I've used. If I replace the offedning line of code with:
Code:
for Station in TubeStationList['metropolitan'].values():
It works fine. So why doesn't it work when I'm passing a value from a listWidget?

Thanks in advance
 
Posts: 432 | Thanked: 645 times | Joined on Mar 2009
#2
Hi,

this is a python unicode-problem. There is a good howto on that. But in general this should do it:

Code:
self.ui.listTubeLine.currentItem().text().encode('ascii','ignore')
Daniel
 

The Following User Says Thank You to danielwilms For This Useful Post:
Posts: 127 | Thanked: 54 times | Joined on Nov 2009
#3
Excellent - I'll give that a shot tonight. many thanks.
 
Posts: 127 | Thanked: 54 times | Joined on Nov 2009
#4
Hmm - tried that but got an error that QList doesn't have a .encode attribute.

I found .toAscii() instead and used that - but it's still not working. I get a similar error as previously although it would appear to be an ascii string rather than unicode as I'm not getting the u beforehand.

Code:
    for Station in TubeStationList[self.ui.listTubeLine.currentItem().text().toAscii()].values():
KeyError: PyQt4.QtCore.QByteArray('district')
Where as the following works fine:
Code:
for Station in TubeStationList['district'].values():
So the key must be in the dictionary - still an ascii to unicode issue?
 
Reply


 
Forum Jump


All times are GMT. The time now is 23:48.