A
A
Andrey Prenrek2021-03-16 15:58:44
Python
Andrey Prenrek, 2021-03-16 15:58:44

How to append data to a file from a new line in python?

Here, I want to append data to the file from a new line, here is my code:

for i in tem:
    f.write(f"{i}"+"\n")


And then I want to add more data, and this is what I get:
6050aaefdeb34016656590.png
After the added word, I have an empty line, and it bothers me, because if I want to display data line by line, an empty line that I don’t need is displayed without data, how to get rid of from these empty lines?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergo Zar, 2021-03-16
@Sergomen

Write without "\n"

Y
Yupiter7575, 2021-03-16
@yupiter7575

try opening the file as add instead of write. Or check the value of the variable i. Perhaps there is already a transfer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question