[PyKDE] sipThis and AttributeError

Laurent Claustre claustre at esrf.fr
Mon Mar 4 11:43:42 GMT 2002


I'v find the following thread from the archive (see below),
and the solution that Tad E. Smith proposed solves the bug.
BUT WHY, should we execute "str(self.__dict__)" ???

There are about now 4 threads in the achive about this strange bug, could
effort be done to solve it?
 Cheers,


Gerard Vermeulen wrote:
 > > Hi,
 > > The following 30-line program (python-2.1, PyQt/sip-2.5pre1, Qt-2.2.1)
 > shows a bug, that goes away if I comment out line 14 and
 > uncomment line 15
 > > --
 > #!/usr/bin/env python
 > > import sys
 > from qt import *
 > > class Item(QListViewItem):
 > def __init__(self, parent, value):
 > QListViewItem.__init__(self, parent)
 > self.value = value
 > > def text(self, column):
 > if column == 0:
 > print self.value[0]
 > return "%4d: %5d %8.2f %8.2f" % self.value[0] # this fails
 > #return "%4d: %5d %s %s" % self.value[0] # this works
 > elif column == 1: return "[%5d, %5d)" % self.value[1]
 > else: return ""
 > > list = [((1, 520, 3.14, 2.72), (13, 17)), ((2, 520, 2.72, 3.14), 
(37, 43))]
 > for item in list:
 > print "%4d: %5d %8.2f %8.2f" % item[0]
 > > app = QApplication(sys.argv)
 > listView = QListView()
 > app.setMainWidget(listView)
 > listView.setCaption('Pourquoi?')
 > listView.addColumn('Settings')
 > listView.addColumn('Zoom')
 > for item in list:
 > Item(listView, item)
 > listView.show()
 > app.exec_loop()
 > --
 > It crashes with
 > --
 > [packer at taco python]$ python bug.py
 > 1:   520     3.14     2.72
 > 2:   520     2.72     3.14
 > (2, 520, 2.7200000000000002, 3.1400000000000001)
 > (1, 520, 3.1400000000000001, 2.7200000000000002)
 > (2, 520, 2.7200000000000002, 3.1400000000000001)
 > (1, 520, 3.1400000000000001, 2.7200000000000002)
 > (1, 520, 3.1400000000000001, 2.7200000000000002)
 > (1, 520, 3.1400000000000001, 2.7200000000000002)
 > (1, 520, 3.1400000000000001, 2.7200000000000002)
 > Traceback (most recent call last):
 > File "bug.py", line 14, in text
 > return "%4d: %5d %8.2f %8.2f" % self.value[0] # this fails
 > AttributeError: sipThis
 > Segmentation fault
 > [packer at taco python]$
 > --
 > > Of course, later, I realized that the (b)right way to do this
 > is to write something like:
 > def __init__(self, parent, value):
 > QListViewItem.__init__(self, parent,
 > "format0" % value[0],  "format1" % value[1])
 > self.value = value
 > > and not to redefine:
 > def text(self, column)
 > > but why does line 14 crash after being executed successfully
 > 7 times?

I've experienced the same error (except that I didn't get a Segmentation
fault)  inside the "toggled()" method in a subclass of PushButton.  There I
was testing for string equality.  The following line solved my problem:
bugWorkaround = str(self.__dict__)
If you insert this before line 14 of this script you no longer get this 
error.

Any ideas?
-- Tad



-- 
	/===============================================================\
	|  Laurent Claustre               | eMail: claustre at esrf.fr     |
	|  BeamLine Instrument Software   | Phone: +33 (0)476 88 29 12  |
	|  Support Group  (BLISS)         | Fax  : +33 (0)476 88 25 42  | 
	|  Experiments        Division    | Central Building Room 150   |
	| ------------------------------------------------------------- |
	|            European Synchrotron Radiation Facility            |
	|   6 rue Jules Horowitz BP220 38042 Grenoble Cedex - France    |
	\===============================================================/






More information about the PyQt mailing list