Answer the question
In order to leave comments, you need to log in
How to get rid of empty lines in file.write()?
Essence of the question. There is a tuple of strings, each line of which starts with characters \r\n.
When outputting a tuple to the console:
for x in tuple:
print(x.decode('cp1251'))
1. one;
2. two;
3. three;
file = open('file.txt', 'a')
for x in tuple:
file.write(x.decode('cp1251'))
1. one;
2. two;
3. three;
Answer the question
In order to leave comments, you need to log in
The problem was the carriage return character "\r".
Decided like this:
for x in tuple:
file.write(x.decode('cp1251').replace('\r\n', '\n'))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question