Question: Objective Create a Python program that manages CSV file operations, uses the os module to interact with the file system, and separates data definition into
Objective
Create a Python program that manages CSV file operations, uses the os module
to interact with the file system, and separates data definition into a module. You
will also create another file called csvdata.py to store all your data that you will
use when creating your CSV file.
Global Variable
Setstring mainpy equal to a global variable called filepath and run that through
the following functions you create
SampleDataDictionary
Create a new file called csvdata.py define a data dictionary with at least fields
and entries, which will be imported into main.py
CSVFileCreation and Reading
Write a function called createcsv to create a CSV file from a data dictionary
imported from csvdata.py
NamedtheCSVfile csvdata.csv
Usecsv.DictWriter to write the data to the CSV file within a with statement
ensuring proper file handling.
File Existence Check
Create a function called fileexists
Usetheos.path.exists module to check if the main.py file exists.
File Metadata
Create a function call filemetadata
Useos.stat to obtain and print the file size and last modified time of main.py
ReadandDisplay CSV Data
Create a function called readcsv
Thisfunction should open the created CSV file and uses csvDictReader within a
with statement to iterate over and print each row.
Useaforloop to iterate through each row in the csv file and print the output on
the console
MainFunction
Create a function called main
Call on all functions that were created through the main function
Remembertocall on the main function to run your python scrip
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
