Request for feedback on my first Python program
Max M
maxm at mxm.dk
Fri May 30 05:31:04 EDT 2003
Ganesan R wrote:
> readlines() will slurp in the whole file into memory.
That is most likely not a problem in this case.
> for line in file:
> if line and line.startswith("#"):
> line.rstrip() # strip \n and other white space
The spec said where the first non-whitespace character is #. This means
that there can be whitespace characters before the #.
So it is better to strip first to remove those.
Also strip() returns a string, it dosn't mutate the one you are in:
for line in file:
line = line.strip()
if line and line.startswith("#"):
# etc.
also:
if line and line.startswith("#"):
Will only give you the comments, it should be:
if line and not line.startswith("#"):
But you could just as well write:
if line and line[0] != "#":
--
hilsen/regards Max M Rasmussen, Denmark
http://www.futureport.dk/
Fremtiden, videnskab, skeptiscisme og transhumanisme
More information about the Python-list
mailing list