In this lab, you will be tasked with writing several functions that do various tasks with file reading and writing.
You should create one file named lab7.py
and put all of the functions you complete, along with the test-cases, in the same file.
Submit just this file to D2L when you are finished.
Write a function named print_first_words .
This function will take one parameter - the name of the file to read.
This function will open the file, read in the data, and print out the first word on each line to the python console, all on the same line.
For example, if there is a file named input1.txt in the same directory as lab7.py with these contents:
|
Write a function named reverse_file .
This function will take one parameter - the name of the file to read.
This function will open the file, read in all of the lines, reverse the order of the lines, and then write over the original file with the reversed content.
For example, if there is a file named input1.txt in the same directory as lab7.py with the same contents as the previous problem, then calling the funciton like so::
|
Write a function named cap_word_count .
This function will take one parameter - the name of the file to read.
This function will return a single integer, which should be the number of capitalized words (words that begin with a capitalized letter) in the file.
For example, if there is a file named input2.txt in the same directory as lab7.py with the these contents:
|
Write a function named grab_csv_column .
This function will take two parameters.
The first is the name of a CSV file to read, and the second is an integer representing a column number.
This function will read in the CSV file, and extract all of the entries of the CSV file that line up with the column number specified, in sorted order.
It should also ignore the first line (the line with the column labels).
For example, if there is a file named data.csv in the same directory as lab7.py with the these contents:
|
You must turn in at least 3 of the problems on D2L to get credit for this.