Re: Method needed for skipping lines
- From: Yu-Xi Lim <yuxi@xxxxxxxxxxxxxx>
- Date: Wed, 31 Oct 2007 16:47:42 -0400
Gustaf 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 imagine having a flag variable to tell whether you're inside the auto-generated part, but I wasn't able to figure out exactly how. Here's the function, without the ability to skip auto-generated code:
# Count the lines of source code in the file
def count_lines(f):
file = open(f, 'r')
rows = 0
for line in file:
rows = rows + 1
return rows
How would you modify this to exclude lines between "Begin VB.Form" and "End" as described above?
Gustaf
David Mertz's Text Processing in Python might give you some more efficient (and interesting) ways of approaching the problem.
http://gnosis.cx/TPiP/
.
- References:
- Method needed for skipping lines
- From: Gustaf
- Method needed for skipping lines
- Prev by Date: Re: 3 number and dot..
- Next by Date: Re: 3 number and dot..
- Previous by thread: Re: Method needed for skipping lines
- Next by thread: Building libraries that my extensions can use. [distutils]
- Index(es):
Relevant Pages
|