Request for feedback on my first Python program
Ganesan R
rganesan at myrealbox.com
Fri May 30 04:33:11 EDT 2003
>>>>> "Scott" == Scott Meyers <Usenet at aristeia.com> writes:
> I'm a C++ programmer who's writing his very first Python program.
Are you "the" Scott Meyers? Wow. Welcome :-).
The python idiom to iterate through lines in a file is
for line in file:
do_something()
readlines() will slurp in the whole file into memory.
> if firstToken[0] != "#":
> nonCommentLines.append(lines[i])
The python idiom for this is if lines[i].startswith("#")
So you can do something like
for line in file:
if line and line.startswith("#"):
line.rstrip() # strip \n and other white space
....
Ganesan
--
Ganesan R (rganesan at debian dot org) | http://www.debian.org/~rganesan/
1024D/5D8C12EA, fingerprint F361 84F1 8D82 32E7 1832 6798 15E0 02BA 5D8C 12EA
More information about the Python-list
mailing list