oldoc63 / learningDS

Learning DS with Codecademy and Books
0 stars 0 forks source link

Appending to a File #357

Open oldoc63 opened 1 year ago

oldoc63 commented 1 year ago

There is a way to just add a line to a file without completely deleting it. Instead of opening the file using the argument 'w' for write-mode, we open it with 'a' for append-mode.

oldoc63 commented 1 year ago

In the code above we open a file object in the temporary variable gen_file. This variable points to the file generated_file.txt and, since it's open in append-mode, adds the line ... and it still is as a new line to the file. If you were to open the file after running the script it would look changed.