[PyKDE] Printing empty QStrings
Phil Thompson
phil at river-bank.demon.co.uk
Tue Oct 31 00:24:09 GMT 2000
Boudewijn Rempt wrote:
>
> Around version 0.10.1 QString started to return None when empty, instead
> of segfaulting. However, with the current version and Python 2.0, there
> is another problem: if you want to print an emtpy QString, you get the
> following:
>
> Python 2.0 (#1, Oct 28 2000, 11:41:22)
> [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
> Type "copyright", "credits" or "license" for more information.
> >>> import qt
> >>> a = qt.QChar()
> >>> print a
> <qt.QChar instance at 0x81d71f4>
> >>> a=qt.QString()
> >>> print a
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/local/lib/python2.0/site-packages/qt.py", line 898, in
> __str__
> return str(self.sipThis)
> TypeError: __str__ returned non-string (type None)
> >>>
>
> I'm not sure what's right - returning None or repr(None) - but this
> used to work.
It's the intended behaviour - but I'm not convinced it is the right
behaviour.
The problem is how to differentiate between a null QString and an empty
QString. The choices are...
1. Keep it as it is and have an empty QString return a zero length
Python string and a null QString return None and trigger an exception.
2. Return a zero length Python string for both empty and null strings
(and use the appropriate QString methods if you really want to know if
it is empty or null).
3. Have a null QString return a Python string something like <null
QString at ...>.
4. Do (2) for str() and (3) for repr().
5. Do something else.
Suggestions?
Phil
More information about the PyQt
mailing list