problem parsing lines in a file

Kees Bakker spam at altium.nl
Wed Dec 12 09:16:56 EST 2007


barronmo wrote:

> I'm having difficulty getting the following code to work.  All I want
> to do is remove the '0:00:00' from the end of each line.  Here is part
> of the original file:
> 
> 3,3,"Dyspepsia NOS",9/12/2003 0:00:00
>...
> 20,3,"Bubonic plague",11/11/2003 0:00:00
> 
> output = open('my/path/ProblemListFixed.txt', 'w')
> for line in open('my/path/ProblemList.txt', 'r'):
>      newline = line.rstrip('0:00:00')
>      output.write(newline)
> output.close()
> 
> 
> This result is a copy of "ProblemList" without any changes made.  What
> am I doing wrong?  Thanks for any help.

You should feel lucky that it didn't work :-) If you would have used
    newline = line.rstrip('0:00:00\n')
you would not have found the problem, nor the solution.
--
Kees




More information about the Python-list mailing list