Not Recognizing Loop Variable in Python
问题 I am trying to delete 38 lines of text after coming across a certain phrase in a .txt file in Python, while still printing the rest of the text. The code I currently have is with open('text_file.txt','r') as f: lines = f.readlines() for line in lines: if "certain_phrase" in line: for num in range(38): del line else: print(line,end='') However, I keep getting the following error: Traceback (most recent call last): File "C:\<location of file>\python_program.py", line 6, in <module> del line