+3 votes
in Programming Languages by (14.6k points)

I am printing lines from a file on the terminal using the print statement. But it prints the newline ("\n") along with the text. How can I drop newline while using the print statement?

1 Answer

+2 votes
by (48.9k points)

You can use the print statement with parameter end="". It will drop the newline from the record.

Here is an example:

>>> with open("pu.txt", "r") as fin:
...     for line in fin:
...             print(line, end="")
import numpy as np
import pandas as pd
from cleanlab.latent_estimation import estimate_latent
from cleanlab.latent_estimation import compute_confident_joint
from cleanlab.classification import LearningWithNoisyLabels
from cleanlab.pruning import get_noise_indices