[PyKDE] Printing empty QStrings

Johannes Sixt Johannes.Sixt at telecom.at
Wed Nov 1 19:58:22 GMT 2000


On Wed, 01 Nov 2000, you wrote:
>Boudewijn Rempt wrote:
>> >>> print (QString())
>> None
>> >>> print (QString(""))
>> 
>> >>> print (QString("a"))
>> a
>> 
>> instead of:
>> 
>> >>> print (QString())
>> 
>> 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)
>
>This is sensible, but can't be achieved. It is Python raising the
>exception (not PyQt) because PyQt is returning the None object instead
>of a string object. PyQt could return a string object containing "None"
>(although "null" would be better) but then 'print QString()' and 'print
>QString("None")' would do exactly the same thing.

IMHO, it is an error to distinguish between an "empty" string and a "null"
string. In a program you usually want that they behave identical
(concatenation, searching, replacing, etc...), they should even compare equal
(if you have 2 string variables, a and b, one contains the empty string, the
other contains the null string, then you want that a==b is true in almost any
case!).

So, why make a difference at all?
<algebra>
My suggestion: treat them both like the neutral element of the monoid of
strings and the concatenation operation, i.e. the so-called emtpy string.
</algebra>

-- Hannes




More information about the PyQt mailing list