Answers for "remove last empty line from file python"

0

remove empty lines from file python

with open("new_file","r") as f:
 for i in f.readlines():
       if not i.strip():
           continue
       if i:
           print i,
Posted by: Guest on November-05-2020
0

remove last line of text file python

fd=open("file.txt","r")
d=fd.read()
fd.close()
m=d.split("n")
s="n".join(m[:-1])
fd=open("file.txt","w+")
for i in range(len(s)):
    fd.write(s[i])
fd.close()
Posted by: Guest on August-18-2020

Code answers related to "remove last empty line from file python"

Python Answers by Framework

Browse Popular Code Answers by Language