First, I use echo 'hello,' >> a.txt
to create a new file with one line looks like that. And I know \n
is at the last of the line.
Then I get some data from python, for example "world", I wish to append "world" at the first line, so I use the python code below:
f = open('a.txt','a')
f.write("world\n")
f.flush()
f.close()
And, here is the result. I know the start point for python to write is at the next line, but I don't know how to fix it.