[PyQt] Missing method for QByteArray and Python3?
detlev
detlev at die-offenbachs.de
Sun Jan 10 13:05:36 GMT 2010
On Sonntag, 10. Januar 2010, Phil Thompson wrote:
> On Sat, 9 Jan 2010 18:33:32 +0100, detlev <detlev at die-offenbachs.de> wrote:
> > Hi,
> >
> > really often I have this kind of code in my application when it comes to
> > converting a QByteArray to s string under Python 3.1.
> >
> > s = bytes(QByteArray).decode()
> >
> > In Python 2 one could use
> >
> > s = unicode(QByteArray)
> >
> > to get the same result. Did I miss something or could QByteArray get a
> > decode() method to make it similar to a Python3 bytes or bytearray type?
>
> The Python3 way to do it is...
>
> s = str(QByteArray, encoding='ascii')
>
> ...or whatever encoding is used.
>
> It would be possible to change things so that...
>
> s = str(QByteArray)
>
> ...automatically uses the default encoding. However that would then make it
> inconsistent with the behaviour of...
>
> s = str(bytes)
>
> ...and I'm not sure that that is a good idea.
>
> Phil
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
Maybe QByteArray should be changed to a mapped type and bytearray should be
used (like the QString change).
Regards,
Detlev
--
Detlev Offenbach
detlev at die-offenbachs.de
More information about the PyQt
mailing list