Re: Method needed for skipping lines



On Wed, 31 Oct 2007 18:02:26 +0100, Gustaf wrote:

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?

Introduce the flag and look up the docs for the `startswith()` method on
strings.

Ciao,
Marc 'BlackJack' Rintsch
.



Relevant Pages

  • Re: Method needed for skipping lines
    ... 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. ... without the ability to skip auto-generated code: ...
    (comp.lang.python)
  • Re: Quirk with generics
    ... to do it by copy-and-paste would have entailed ... Creating a new project in my IDE. ... Creating four new source files within the package. ...
    (comp.lang.java.programmer)
  • IDE / Server file permission problem?
    ... My development environment is set up with project & source files on a ... I now find that apps blows up with the ... from the IDE or as a built .exe on the network drive. ...
    (microsoft.public.dotnet.general)
  • Re: Problem on build
    ... when you do a build you are more or less recompiling all of your source files ... while ur in the IDE it likes to cache up things so usually only the changed ... if you do a REBUILD all, then it compiles everything... ... To See what real programmers do in their spare time visit ...
    (borland.public.delphi.ide)
  • Re: zip.add not working in app from D2006/vista IDE
    ... If I use the support utility (from IDE) all goes well. ... If I "run without debugging" in the IDE the error is there. ... of all my source files and also my experience is that if I ignore ...
    (alt.comp.lang.borland-delphi)