[Tutor] Logic error / poor understanding of classes?

Alan Gauld alan.gauld at freenet.co.uk
Tue Nov 30 12:58:03 CET 2004

>     def sortAndTuple(self):
>         listOTuples=self.cmList.items()
>         print listOTuples
>         print 'List presort'
>         print self.sortSetting
>         if self.sortSetting == 0:
>         elif self.sortSetting == 1:
> [('Carla', 'ECM'), ('Dave', 'ABC') <etc. etc.> ]
> List presort
> 0
> z point
> None
> So my expected list of tuples is fine, and self.sortSetting is 0, as
> it should be...

Are you sure?
It looks to me like sortSetting might be '0' - a string - and
so neither of the two clauses in the function get called and it
therefore returns the default value of None....

Just a guess though... Try running it in the debugger and steping
through the code with a watch on sortSetting to check its value
(and type!). This is the kind of problem debuggers are designed
for :-)

Alan G.

More information about the Tutor mailing list