O'Reilly logo

The Art of Debugging with GDB and DDD by Peter Jay Salzman, Norman Matloff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Python

Let's take as our example tf.py, which counts words, lines, and paragraphs in a text file, as with our Perl example above.

Perl debugging screen

Figure 8-5. Perl debugging screen

 1 class textfile: 2 ntfiles = 0 # count of number of textfile objects 3 def __init__(self,fname): 4 textfile.ntfiles += 1 5 self.name = fname # name 6 self.fh = open(fname) 7 self.nlines = 0 # number of lines 8 self.nwords = 0 # number of words 9 self.npars = 0 # number of words 10 self.lines = self.fh.readlines() 11 self.wordlineparcount() 12 def wordlineparcount(self): 13 "finds the number of lines and words in the file" 14 self.nlines = len(self.lines) 15 inparagraph = 0 16 for l in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required