Changes

Jump to: navigation, search

OPS435 Python Lab 5

162 bytes added, 07:24, 5 September 2017
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>
13,420
edits

Navigation menu