[Tutor] Class reference problem?

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Sat Jun 4 03:18:27 CEST 2005



On Fri, 3 Jun 2005, spartan-ii at tds.net wrote:

> for item in function1(args):
>      object = class()
>      if (function2(item)):
>          if (condition):
>              object.variable = value
>              object.function()
>              print object # debug
>      print object #debug
>
> The above pseudo code (not really, but close enough) is essentially what
> I'm playing with. I hope it gives a sense of what I'm trying to do.


Hello!


Hmmm... you may want to modify the print statements slightly to make it
more clear which of the two print statements are being displayed.  That
is, I'd recommend you distinguish the debug statements by putting some
kind of mark, like:

######
for item in function1(args):
     object = class()
     if (function2(item)):
         if (condition):
             object.variable = value
             object.function()
             print "inner", object # debug
     print "outer", object #debug
######


As the code stands, it's not clear that 'condition' is ever set to true.
When you mention that:

    > Any way, the debug lines both print "<__main__.CLASSNAME instance at
    > ADDRESS>" like they should, but the addresses never match up.

there is one alternative explanation for what you're seeing: it's possible
that all of the print statements are coming off the outer print statement
alone, and that neither the 'function2()' nor 'condition' branches are
being taken.

I just want to make sure you're testing what you think you're testing.
*grin*


Best of wishes to you!



More information about the Tutor mailing list