13,420
edits
Changes
→PART 2 - Writing To Files
::#Issue the following commands:<source lang="python">
f = open('file2.txt', 'w')
f.write('Line 1\nLine 2 is a little longer\nLine 3 is tooas well\n')
f.write('This is the 4th line\n')
f.write('Last line in file\n')
Line 1
Line 2 is a little longer
Line 3 is too as well
</source>
::#In the event that the data in the file is important and should not be overwritten, we can append data to the end of the file instead. Use the option 'a' instead of 'w' to perform appending.<source lang="python">