I have a variable (aTerm) which contains an 8 digit random number which im using to uniquely identify each individual line of a csv file.
Here is the code I wrote to remove the line which has the corresponding number:
def rebuildFile(aTerm, aFile):
with open(aFile, 'r') as oldFile, open('static\\new.csv', 'w') as newFile:
for line in oldFile:
if not aTerm in line:
newFile.write(line)
return
The only trouble is that it doesn't work at all unless I type out the 8 digit number as a string in the if statement. So this works perfectly:
def rebuildFile(aTerm, aFile):
with open(aFile, 'r') as oldFile, open('static\\new.csv', 'w') as newFile:
for line in oldFile:
if not "45893243" in line:
newFile.write(line)
return
I don't understand and would greatly appreciate the help thanks