[PyKDE] QString -> python string via QString::latin1()

Jim Bublitz jbublitz at nwinternet.com
Thu Oct 6 21:19:16 BST 2005


On Thursday 06 October 2005 12:26, Phil Thompson wrote:
> On Thursday 06 October 2005 7:17 pm, Nigel Stewart wrote:

> > Contrast this with the PyQt binding for
> >
> > the str() converter:
> >  >> print type(str(qt.QString("foo")))
> >
> > <type 'str'>
> >
> >  >> print type(str(qt.QString("")))
> >
> > <type 'str'>
> >
> >  >> print type(str(qt.QString.null))
> >
> > <type 'str'>
> >
> >  >> print type(str(qt.QString()))
> >
> > <type 'str'>
> >

> Null and empty QStrings are different and the PyQt behaviour reflects the
> Qt behaviour.
>
> > I'm interested in the broader
> > PyKde/PyQt opinion, is it "pythonic" to return
> > different types of objects, depending on the
> > input?

> str() is defined to return a string object. If there is a bug then it's
> that str() of a null string should raise an exception. I'd be willing to
> implement that for PyQt4

str(None) and str("") both return string type as well - the only exception 
thrown appears to be for a malformed argument, eg str (1z2). Seems like the 
behavior is consistent as is.

Jim




More information about the PyQt mailing list