mpmackenna mpmackenna - 8 months ago 42
Python Question

No newline character at end of file even after writing it

# Create strings for preparation of file writing
s = ";"
seq = (risd41Email, risd41Pass, rimsd41Email, rimsd41Pass);
textString = s.join(seq);

# Create file, write contents, move to usertxtfiles dir
with open(filename, "w") as text_file:

os.rename(fileMigPath, fileDestPath)

I have the above code that clearly writes a newline to the file I am editing. When I try to use the file another script does not execute the line because there is no newline character at the end of the file. If I copy the file and then open it in vi and then save it, vi adds a newline character and the line of the file executes properly. If I run diff between the file that wasn't saved in vi versus the one that was I get the message that the difference is no newline at end of file. I am using Python 2.7.12 on Ubuntu server Xenial.


Try that:


This should work!