=== 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 that you created).::#Add the following functions below the two functions that you already created:<source lang="python">
def append_file_string(file_name, string_of_lines):
# Takes two strings, appends the string to the end of the file
# 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 (i.e. the boiler-plate) near the bottom with the following:<source lang="python">
if __name__ == '__main__':
file1 = 'seneca1.txt'
</source>
:::'''append_file_string():'''::::#Takes '''two string arguments'''::::#'''Appends''' to the file(Argument 1) all data from the string(Argument 2):::'''write_file_list():''' ::::#Takes two arguments: a '''string''' and a '''list'''::::#'''Writes''' to file(Argument 1) all lines of data found in the list(Argument 2):::'''copy_file_add_line_numbers():'''::::#Takes two arguments: '''Both are files path-names''' (which happen to be strings)::::#'''Reads''' all data from first file(Argument 1), and writes all lines into second file(Argument 2) '''adding''' line numbers::::#Line numbers should be added to the '''beginning''' of each line with a colon next to them(see sample output below for reference)::::#'''Hint:''' Review Use an extra variable for the '''len()''' and '''range()''' functions from '''lab 3''' and '''lab 4'''line number
::::'''Sample Run 1:'''<source lang="python">
python3 lab5b.py
First Line
</source>
::::'''Sample Run 2 (with import):'''<source lang="python">
import lab5b
file1 = 'seneca1.txt'
</source>
:::3. Exit the ipython3 shell, download the checking script and check your work. Enter the following commands from the bash shell.<source lang="bash">
cd ~/ops435/lab5/
pwd #confirm that you are in the right directory
python3 ./CheckLab5.py -f -v lab5b
</source>
:::4. Before proceeding, make certain that you identify any and all errors in lab5b.py. When the checking script tells you everything is OK before proceeding to the next step.
<br><br>