Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing to the end of a text file in python 3 [duplicate]

Tags:

python

text

I'm currently working on a bit of code that requires me to keep records of the outcome. However, at the minute, the code I'm using only overwrites the document, rather than adding on. What can I write to add something to the end of a text document?

like image 575
user3341402 Avatar asked Dec 15 '14 15:12

user3341402


People also ask

How do you duplicate a text file in Python?

The shutil. copy() method in Python is used to copy the content of the source file to destination file or directory.

How do I put text in a specific position of a file in Python?

seek() method In Python, seek() function is used to change the position of the File Handle to a given specific position. File handle is like a cursor, which defines from where the data has to be read or written in the file.

How do you close a write in Python?

Closing a file in Python Python has a close() method to close a file. The close() method can be called more than once and if any operation is performed on a closed file it raises a ValueError. The below code shows a simple use of close() method to close an opened file.


1 Answers

open the file in append mode

open(filename, 'a')
like image 129
ch3ka Avatar answered Nov 12 '22 17:11

ch3ka