+ 3

How to add new text to an existing file..?

Here while i try to modify the biography how can i add new text to the existing one https://code.sololearn.com/c4ALziaPmSkl/?ref=app

6th Aug 2019, 9:35 AM
Y AD Ù
Y AD Ù - avatar
6 Réponses
+ 8
This a tutorial i posted 5 months ago that will cover most of your needs: https://code.sololearn.com/cESZeFlM1cRR/?ref=app
6th Aug 2019, 10:59 AM
Lothar
Lothar - avatar
+ 5
Y Åđ Û As far as I know, Sololearn deletes your created file immediately after code execution. In other words, it's useless trying to modify a file because the file is never saved in the first place. If you still like to test, here's my tweaked version of your code https://code.sololearn.com/cDSyLm4vR6jS/?ref=app
6th Aug 2019, 10:18 AM
Dlite
Dlite - avatar
+ 5
use with... with open("path/to/file", a) as text: do something() You dont have to worry about close. The argument mode points to a string beginning with one of the following sequences (Additional characters may follow these sequences.): ``r'' Open text file for reading. The stream is positioned at the beginning of the file. ``r+'' Open for reading and writing. The stream is positioned at the beginning of the file. ``w'' Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. ``w+'' Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file. ``a'' Open for writing. The file is created if it does not exist. The stream is positioned at the end of the file. Subsequent writes to the file will always end up at the then current end of file, irrespective of any intervening or similar. ``a+'' Open for reading and writing. The file is created if it does not exist
6th Aug 2019, 10:20 AM
Steven M
Steven M - avatar
+ 4
here some more informations according file read / write: r+ opens for reading and writing (no truncating, file pointer at the beginning) Here is an other tutorial for this issue: https://www.pythonforbeginners.com/files/reading-and-writing-files-in-JUMP_LINK__&&__python__&&__JUMP_LINK
7th Aug 2019, 7:44 AM
Lothar
Lothar - avatar
+ 3
Y Åđ Û, stream=pointer=cursor. A "stream" refers to elements made available over time. A stream can be thought of as items on a conveyor belt being processed one at a time rather than in large batches.
7th Aug 2019, 10:08 AM
Steven M
Steven M - avatar
+ 1
n3v375 bruhh..what did u mean by 'the stream is positioned at the beginning of the file'..while u were telling about r+..?
7th Aug 2019, 5:25 AM
Y AD Ù
Y AD Ù - avatar