Confused again

Duncan Smith buzzard at urubu.freeserve.co.uk
Mon Feb 24 10:03:19 EST 2003


"Alex Martelli" <aleax at aleax.it> wrote in message
news:pzk6a.302915$AA2.11520637 at news2.tin.it...
> Duncan Smith wrote:
>    ...
> > after calling the function, the exception is apparently ignored.  eg.
the
>
> Hard to say, because you don't show the rest of the function
> containing this raise statement, the definition of the Error
> class you raise, etc.  It's likely that somewhere in the
> parts you don't show you have a try statement that is swallowing
> up the exception you're raising here.
>
>
> Alex
>

Doh!  You're right Alex.  Now I've admitted my stupidity I might as well
post a complete function.  If eg. "table =
numtable1.margTo(numtable2.variables)" doesn't raise an exception I want to
test "table" and "numtable2" for equality, and raise an exception if they
aren't equal.  I can sort this out now, but I'd be interested to see any
particularly elegant ways of getting the behaviour I'm after.  Cheers Alex.

p.s. Thanks also to Steven, and is there any detailed guidance available on
overloading operators?  I've read the documentation and had a Google, but
there's still a few things I'm not clear about.  ie. Steven sorted out my
immediate problem (posted the day before last), but I'm still not 100% sure
how I got a returned value of 0 when my code would appear to return 1.
Cheers.

Duncan

    def pruneTables(self):

        """Removes superfluous margins from self.tables
        and checks for inconsistencies"""

        # remove duplicates
        for numtable in self.tables[:]:
            duplicates = self.tables.count(numtable)
            for i in range(duplicates - 1):
                self.tables.remove(numtable)
        # check for inconsistencies and remove sub-margins
        pairs = iter.iterPairs(range(len(self.tables)))
        to_remove = []
        for pair in pairs:
            numtable1 = self.tables[pair[0]]
            numtable2 = self.tables[pair[1]]
            try:
                table = numtable1.margTo(numtable2.variables)
                if table == numtable2:
                    to_remove.append(table)
                else:
                    raise 'An inconsistency in cluster %s' % str(self.id)
            except:
                try:
                    table = numtable2.margTo(numtable1.variables)
                    if table == numtable1:
                        to_remove.append(table)
                    else:
                        raise 'An inconsistency in cluster %s' %
str(self.id)
                except:
                    pass
        for numtable in to_remove:
            self.tables.remove(numtable)








More information about the Python-list mailing list