13,420
edits
Changes
→PART 2 - Writing To Files
::#To confirm that the new file exists and is empty, issue the following command:<source lang="python">
ls -l file1.txt
</source>::#<br>To add lines of text to the file, you would use the '''write() ''' method for the '''file object'''. For safe file management, always end every line with a the special character ''''\n'''' to represent a "new line". Multiple lines may also be placed inside a single write, operation: simply put the '\n' wherever a line should end.<br><br>::#To demonstrate adding multiple lines, issue the following command:<source lang="python">
f.write('Line 1\nLine 2 is a little longer\nLine 3 is too\n')
</source>