I am currently appending like this:
with open(filename, "a") as fh:
fh.write("some line")
This assumes that the last line of the file is a new line and that it is empty
in the case where the file doesn't end with a new line, my code appends to the last line
i.e.
last line of textsome line
and not:
last line of text
some line
in the case where the file ends with many "empty" new lines, the line is added after them , which isn't good either.
i.e.
...
...
last line
\n
\n
\n
...
some line
I want my line to be added on a new line after the last meaningful existing line (line with text that is non-empty)
The text files are quite large, 10-20 gigs each , so I can't easily "read" and then "chomp".
I know that the files won't have more then 1-10 empty lines at the end (usually only a single empty line at the end hence the code usually works and rarely fails)
is there a variation on open (file, 'a')
to seek to end of content of file on a new line?