Replace line in text file using python - Stack Overflow
stackoverflow.com › questions › 62229766Jun 06, 2020 · filetest = open ("testingfile.txt", "r+") ID = input ("Enter ID: ") list = ['Hello', 'Testing', 'File', 543210] for line in filetest: line = line.rstrip () if not ID in line: continue else: templine = '\t'.join (map (str, list)) filetest.write (line.replace (line, templine)) filetest.close () I'm trying to replace an entire line containing the ID entered in filetest with templine (templine was a list joined into a string with tabs), and I think the problem with my code is specifically this ...