[PyQt] Different Behavior between Python 2.6 and Python 3.1.1

Giovanni Bajo rasky at develer.com
Wed Jan 13 09:23:35 GMT 2010


On Tue, 12 Jan 2010 23:38:20 +0000 (UTC), Richard Parker
<r.richardparker at comcast.net> wrote:

> 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? 

The change you see is PyQt API v2 versus PyQt API v1. It is a non-backward
compatible API change.

The decision was to leave API v1 the default for Python 2.x, and make API
v2 the default for Python 3.x. But this is just the default! You can change
API version by using:

  import sip
  sip.setapi('QString', 1)  # or 2

Do this at the very beginning of your program, before doing anything else
with PyQt. So, if you are writing a new program and you want to be as
future-proof as possible, I suggest you explicitly select version 2 even
for Python 2.x, and write your code to adhere API v2.

On the other hand, if you're just porting your existing Python 2.x
application to Python 3.x, and you expect to change as little code as
possible, explicitly force API v1 even for Python 3.x.

Read the documentation about other incompatible changes here:
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt4ref.html#selecting-incompatible-apis
-- 
Giovanni Bajo
Develer S.r.l.
http://www.develer.com


More information about the PyQt mailing list