Changes

Jump to: navigation, search

OPS435 Python Lab 5

130 bytes added, 08:18, 5 September 2017
PART 2 - Writing To Files
::#Let's open a non-existent file (called file1.txt) for writing. Issue the following command:<source lang="python">
f = open('file1.txt', 'w')
</source>
::#To confirm that the new file exists and is empty, issue the following command:<source lang="python">
ls -l file1.txt
</source>
::#To add lines of text to the file, use the write() method for the file object. For safe file management, always end every line with a '\n'. Multiple lines may also be placed inside a single write, simply put the '\n' wherever a line should end.<source lang="python">
13,420
edits

Navigation menu