remove line python code example
Example 1: python remove new line
lines = ("line 1 \r\n")
lines.rstrip("\n\r")
Example 2: python read and delete line from file
with open("yourfile.txt", "r") as f:
lines = f.readlines()
with open("yourfile.txt", "w") as f:
for line in lines:
if line.strip("\n") != "nickname_to_delete":
f.write(line)
Example 3: python remove lines of string
output_String = input_String.split("\n", 1)[1]
output_String = input_String.split("\n", 3)[1]
output_String = input_String.split("\n", 4)[0]