Reputation: 97
i need to use
for line in doc.split('\n'):
and do some operation on each line but i got at the end of the file empty line as i think it split a new line every time ! how can i avoid this problem ?
Upvotes: 0
Views: 35
Reputation: 51
Please rephrase your question, since it is not very clear.
Anyway, if you are working with a text file you can just use:
with open("path_to_soruce_textfile", "r") as src, open("path_to_dest_textfile", "w") as dst:
for line in src.readlines(): # this gives you a list of lines with each line finishing with \n
processed_line = modidy(line)
dst.write(processed_line) # make sure \n is at the end of each line when you write
# the file is automatically closed
Upvotes: 1