Page 1 of 1

[closed] syntax to append data to textfile

Posted: Tuesday 07 March 2023 23:20
by BartSr
I am struggeling to get data append to existing textfile

Code: Select all

 file = io.open("/home/pi/gas.txt", "w+") 
   	file:write("gasstand"..gasstand.."\n")
        file:close() --closes the open file
I borrowed this code partly from a script written by Waaren. It was understood thet the w+ should open the file in append mode.
But every time there is only the new data in the file gas.txt

Where is my error? And where can I find info re create a file if not already exist? To my knowledge quit native but the syntax.....

Thanks
-Bart

Re: syntax to append data to textfile

Posted: Tuesday 07 March 2023 23:30
by Toulon7559
See the first list under this weblink:
https://www.tutorialspoint.com/python/p ... les_io.htm#

Re: syntax to append data to textfile

Posted: Tuesday 07 March 2023 23:43
by BartSr
Toulon7559, Thanks a lot. You helped me out!
-Bart