Method needed for skipping lines

Anand anandology at gmail.com
Wed Oct 31 21:25:22 EDT 2007


On Nov 1, 5:04 am, Paul Hankin <paul.han... at gmail.com> wrote:
> On Oct 31, 5:02 pm, Gustaf <gust... at algonet.se> wrote:
>
> > Hi all,
>
> > Just for fun, I'm working on a script to count the number of lines in source files. Some lines are auto-generated (by the IDE) and shouldn't be counted. The auto-generated part of files start with "Begin VB.Form" and end with "End" (first thing on the line). The "End" keyword may appear inside the auto-generated part, but not at the beginning of the line.

I think we can take help of regular expressions.

import re

rx = re.compile('^Begin VB.Form.*^End\n', re.DOTALL|re.MULTILINE)

def count(filename)
    text = open(filename).read()
    return rx.sub('', text).count('\n')




More information about the Python-list mailing list