[PyQt] Different Behavior between Python 2.6 and Python 3.1.1
Richard Parker
r.richardparker at comcast.net
Tue Jan 12 23:38:20 GMT 2010
Demetrius,
I think you are right, but how can I achieve the same functionality with Python 3.1.1, as I do with Python 2.6? (i.e., left(5).toUpper()) for the "str" that's returned by Python 3.1.1?
I looked at "[0:0<5]".format(self.ui.txtText.text())" and that seemed to work, although it didn't implement the "toUpper() feature and I really need a solution that will do so. I also have another string from a QLineEdit object that I want to convert to an integer value and I had written it as follows:
numbering = self.ui.txtNumber.text().toInt()
But this also fails with an error on Python 3.1.1, indicating that a "str" object has on attribute "toInt()". So, basically, I need to convert both of these to be compatible with Python 3.1.1 and I'm not sure how to do so. Any help will be appreciated.
-rich-
----- Original Message -----
From: "Demetrius Cassidy" <dcassidy36 at mass.rr.com>
To: "Richard Parker" <r.richardparker at comcast.net>
Cc: "PYQT" <pyqt at riverbankcomputing.com>
Sent: Tuesday, January 12, 2010 2:49:41 PM GMT -08:00 US/Canada Pacific
Subject: Re: [PyQt] Different Behavior between Python 2.6 and Python 3.1.1
I think .text() in Python 3.1 with PyQt4 is returning a python 'str'
object, instead of a QString. Try and do type(self.ui.txtText.text())
and see what it returns.
Richard Parker wrote:
> I have the following statement in an application that runs fine with
> Python 2.6 (and PyQt):
>
> text = self.ui.txtText.text().left(5).toUpper()
>
> In Python 3.1.1 (with PyQt), I get the following error for the first
> statement:
>
> " text = self.ui.txtText.text().left(5).toUpper()
> AttributeError: 'str' object has no attribute 'left' "
>
>
> The "ui.txtText.text" object is a QLineEdit object, whose
> documentation indicates that its "text()" function returns a QString
> object, whose documentatation states that the "left(self, n)" and
> "toUpper() functions are supported. What has changed between Python
> 2.6 and Python 3.1 that would account for this error?
>
> Thanks.
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100112/87138138/attachment.html>
More information about the PyQt
mailing list