13,420
edits
Changes
→Create a Python Script Demonstrating Writing to Files
:'''Perform the Following Instructions'''
::#Copy '''~/ops435/lab5/lab5a.py''' script to '''~/ops435/lab5/lab5b.py''' script. We need the previous read functions written.
::#Use Add the following as a templatefunctions below the two functions that you already created:<source lang="python">#!/usr/bin/env python3 def read_file_string(file_name): # This is the same code from lab5a.py def read_file_list(file_name): # This is the same code from lab5a.py
def append_file_string(file_name, string_of_lines):
# Takes two strings, appends the string to the end of the file
def copy_file_add_line_numbers(file_name_read, file_name_write):
# Takes two strings, reads data from first file, writes data to new file, adds line number to new file
</source>::# '''Replace''' the main section of your Python script near the bottom with the following:<source lang="python">
if __name__ == '__main__':
file1 = 'seneca1.txt'
copy_file_add_line_numbers(file2, file3)
print(read_file_string(file3))
</source>
:::'''append_file_string()'''