I am trying to open a file and get the list of all the invalid ids from the lines in it..once I find the invalid ids..i want to delete the whole line(it has multiple ids) if if one id is invalid...i could reach to point of finding invalid ids..i need inputs on how to delete the line from the file or write the remaning good lines into a new file..i have the sample input and expected output below...can anyone provide inputs?
import os
import sys
import time
import simplejson as json
from sets import Set
import operator
import unicodedata
import getopt
'''
list.txt
350882 348521 350166
346917 352470
360049
'''
'''
EXPECTED OUTPUT:-
346917 352470
360049
'''
def func (GerritId):
if GerritId == '350166':
value = "GERRIT IS INCOMPLETE"
else:
value = "GERRIT LOOKS GOOD"
return value
gerrit_list=[]
invalid_gerrit = []
cherry_pick_list = [' ']
with open('list.txt','r') as f :
for line in f :
gerrit_list = line.split(' ')
print "line"
print line
print "gerrit_list"
print gerrit_list
for GerritId in gerrit_list :
GerritId = GerritId.strip()
print "GerritId"
print GerritId
#returnVal = RunCheckOnGerrit_Module.GerritCheck(GerritId)
#GerritInfoItem['GerritId'] = GerritInfoItem['GerritId'] + "\n"
returnVal = func(GerritId)
#print "returnVal"
#print returnVal
if returnVal in ('GERRIT IS INCOMPLETE' or 'NOTHING IS SET' or 'TO BE ABANDON OR NEEDS RESUBMISSION') :
print returnVal
invalid_gerrit.append(GerritId)
else:
print returnVal
print invalid_gerrit
with open('list.txt','r') as f :
for line in f :
#delete the whole line if any invalid gerrit is presnet
gerrit_list = line.split(' ')
print "line"
print line
print "gerrit_list"
print gerrit_list
for GerritId in invalid_gerrit:
GerritId = GerritId.strip()
#delete the whole line if any invalid gerrit is presnet