Thanks Alex,
This helped.

Mario Ontiveros



-----Original Message-----
From: Alex Kleider [mailto:aklei...@sonic.net] 
Sent: Wednesday, February 20, 2019 10:20 PM
To: Mario Ontiveros
Cc: tutor@python.org; Tutor
Subject: [EXTERNAL] Re: [Tutor] Help Please

On 2019-02-20 06:30, Mario Ontiveros wrote:
> Hello,
>     I am new to python and have been stuck on this for a while. What I
> am trying to do is to remove rows with void, disconnected, and error
> on lines. The code I have does that, the only problem is that it
> removes my header because void is in header. I need to keep header.
> 
> Any help will be greatly appreciated.
> 
> with open("PSS.csv","r+") as f:
>     new_f = f.readlines()
>     f.seek(0)
>     for line in new_f:
>         if "Void" not in line:
>             if "Disconnected" not in line:
>                 if "Error" not in line:
>                  f.write(line)
>     f.truncate()
> 
> 
> 
> Mario Ontiveros

Since your file seems to be a csv file, can we assume your 'header' line 
is really a comma separated list of column names?

If so, then using the csv module and specifically csv.DictReader (+/- 
DictWriter) might make things easier for you.


---------------------------------------------------------------------------------------
Confidentiality Warning: This message and any attachments are intended only for 
the 
use of the intended recipient(s), are confidential, and may be privileged. If 
you are 
not the intended recipient, you are hereby notified that any review, 
retransmission, 
conversion to hard copy, copying, circulation or other use of all or any 
portion of 
this message and any attachments is strictly prohibited. If you are not the 
intended 
recipient, please notify the sender immediately by return e-mail, and delete 
this 
message and any attachments from your system.
---------------------------------------------------------------------------------------
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to