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.
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 = ...
Get The Art of Debugging with GDB, DDD, and Eclipse now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.