Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5973

Re: count strangeness

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: count strangeness
Date 2011-05-22 09:36 -0400
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-3A556B.09365022052011@news.panix.com> (permalink)
References <ira8ti$6no$1@dont-email.me>

Show all headers | View raw


In article <ira8ti$6no$1@dont-email.me>,
 James Stroud <jstroud@mbi.ucla.edu> wrote:

> tal 65% python2.7
> Python 2.7.1 (r271:86832, May 21 2011, 22:52:14)
> [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> py> class C(object):
> ...   def __init__(self):
> ...     self.data = []
> ...   def doit(self, count=0):
> ...     for c in self.data:
> ...       count += c.doit(count)
> ...     count += 1
> ...     print count
> ...     return count
> ...
> py> c = C()
> py> c.data.extend([C() for i in xrange(10)])
> py> c.doit()

I have no idea what this is *supposed* to be doing, so let me toss out 
some general debugging ideas;

1) What do you expect [C() for i in xrange(10)] to return?  Does it?  
Run that part in isolation and see if it does.

2) What do you expect c.data.extend([...]) to return?  Does it?

3) What do you expect c.doit() to return for trivial inputs?  Does it?  
Try calling it with a count of 0, 1, and 2, and see if you get the 
result you expect.

In other words, break the problem down into smaller pieces and make sure 
each piece works in isolation.  When you find some little piece which 
isn't doing what you expect, it'll be much easier to debug than trying 
to debug the whole thing at once.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

count strangeness James Stroud <jstroud@mbi.ucla.edu> - 2011-05-21 23:02 -0700
  Re: count strangeness Chris Rebert <crebert@ucsd.edu> - 2011-05-21 23:27 -0700
    Re: count strangeness James Stroud <jstroud@mbi.ucla.edu> - 2011-05-21 23:32 -0700
      Re: count strangeness James Stroud <jstroud@mbi.ucla.edu> - 2011-05-21 23:39 -0700
      Re: count strangeness Chris Rebert <crebert@ucsd.edu> - 2011-05-21 23:55 -0700
        Re: count strangeness James Stroud <jstroud@mbi.ucla.edu> - 2011-05-22 00:03 -0700
  Re: count strangeness Peter Otten <__peter__@web.de> - 2011-05-22 08:31 +0200
    Re: count strangeness James Stroud <jstroud@mbi.ucla.edu> - 2011-05-21 23:34 -0700
      Re: count strangeness Peter Otten <__peter__@web.de> - 2011-05-22 09:13 +0200
    Re: count strangeness James Stroud <jstroud@mbi.ucla.edu> - 2011-05-21 23:56 -0700
  Re: count strangeness Roy Smith <roy@panix.com> - 2011-05-22 09:36 -0400

csiph-web