Changes

Jump to: navigation, search

OPS435 Python Lab 5

2 bytes added, 09:42, 5 September 2017
PART 2 - Writing To Files
f.close()
</source>
::#View Issue the following command to confirm that the contents of the were written to file2.txt to make sure the write data was saved.:<source lang="python">
cat file2.txt
</source>
f = open('file2.txt', 'w')
cat file2.txt
</source>You should notice that the previous content in your file2.txt file was destroyed. Why do you you think the previous data was destroyed?<br><br></li>
<li>Issue the following commands to restore your file from the backup and verify the backup restoration:<source lang="python">
cp file2.txt.bk file2.txt
cat file2.txt
</source><br>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.<br><br></li>
<li>To demonstrate, issue the following commands:<source lang="python">
f = open('file1.txt', 'a')
13,420
edits

Navigation menu