[PyKDE] QString to Python string conversion trouble

Andreas Gerstlauer gerstl at ics.uci.edu
Thu Oct 25 23:46:31 BST 2001


Boudewijn Rempt <boud at valdyas.org> said:
>
> I'm just now revising that chapter - and I would really like to have
> both str(QString("\u4011\u4012")) and unicode(QString("\u4011\u4012"))
> return the same Python Unicode object, that contains the right characters,
> prefarably not an unicode-escape-encoded plain Python string.
> 
But str() will always return a string object, not a unicode object (str() 
returns a string, unicode() a unicode Python object), no?. That's
how str() (vs. unicode()) is defined in Python, isn't it? Changing that
would require changing the Python interpreter itself...
(and also, for example, if you do 'str(u"...")' in normal Python you will
get a string object, not a unicode object)

What will hopefully be the future implementation is that unicode() returns
a Python unicode with the right characters (no encoding) and str() returns
a Python string using the default encoding for any unicode characters (> 128)
(with the possibility of an exception if there are chars > 128 and default
encoding is left at ASCII). That would be desired IMHO. 

Andreas









More information about the PyQt mailing list