On Nov 1, 5:04 am, Paul Hankin <[EMAIL PROTECTED]> wrote:
> On Oct 31, 5:02 pm, Gustaf <[EMAIL PROTECTED]> 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')
--
http://mail.python.org/mailman/listinfo/python-list