I have a text file from which I want to delete all data up to the point where I see the value 'NODATACODE' . The text in the text file is:
MMMMM ; MMMMM : MMMMMMMMMMN, AAAAAAAAAAA,52, AAAA,CCCCCC, MMMMM ; MMMMM : MMMMMMMMMMN,
>AAAAAAAAAAA,200, AAAA,CCCCCC,;MMMMM ; MMMMM : MMMMMMMMMMN, AAAAAAAAAAA,53,
>AAAA,CCCCCC,AAAA AAAAA AAAAAAAAAAA AAAAAAAAAAA AAAAAAAAAAA NODATACODE, : Food Meal
Please let me know how I can rewrite the following code in Python to perform this task. I tried the following code but it doesn't work:
with open('Schedule.txt', 'w') as fw:
for line in lines:
if line.strip('\n') = 'NODATACODE':
fw.write(line)
Error message that I get is below:
Cell In[1], line 5
if line.strip('\n') = 'NODATACODE':
^
SyntaxError: cannot assign to function call here. Maybe you meant '==' instead of
'='?
Original Output
Desired Output
Thank you in advance.


!=, but this is a wild guess since your question is not clear enough. In that file are those lines separated by line breaks? Are there more lines after "NODATACODE"? The indentation is wrong. And I think you might need a read handle to get all the lines first, close it and write handle to write the lines you want.