Changes

Jump to: navigation, search

OPS435 Python Lab 5

No change in size, 08:22, 5 September 2017
PART 2 - Writing To Files
cat file2.txt
</source>
<blockquote style="margin-left:35px;">{{Admon/important|style="padding-left:25px"|Make Backup Copies of Your Data Files|Since you might make a mistake, and accidentally destroy file contents when writing to your file, it is highly recommended to make backup copies of your files prior to running your Python scripts. This can be particularly useful when performing any future assignment involving writing to files.}}</blockquote><br><ol style="margin-left:35px80px;"><li value="9">Issue the following command to backup both of your newly-created files and confirm backup:<source lang="python">
cp file1.txt file1.txt.bk
cp file2.txt file2.txt.bk
f = open('file2.txt', 'w')
cat file2.txt
</source><br>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
13,420
edits

Navigation menu