python remove newline from string code example

Example 1: python removing \n from string

line = line.strip('\n')
line = line.strip('\t')

Example 2: python strip newline from string

a_string = a_string.rstrip("\n")

Example 3: python remove new line

lines = ("line 1 \r\n")
lines.rstrip("\n\r")

Example 4: python replace newline

from tika import parser

filename = 'myfile.pdf'

# Parse the PDF
parsedPDF = parser.from_file(filename)

# Extract the text content from the parsed PDF
pdf = parsedPDF["content"]

# Convert double newlines into single newlines
pdf = pdf.replace('\n\n', '\n')

#####################################
# Do something with the PDF
#####################################
print (pdf)

Example 5: python how to remove n from string

mylist = []
# Assuming that you have loaded data into a lines variable. 
for line in lines:
    mylist.append(line.strip().split('\t')