read the CSV file into my main code
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Please help - I cannot get my fileIO.py to read the CSV file into my main code. Please let me know if I’m doing soemthing incorrect, I have all files in the same file as well.
![File Edit Format Run Options Window Help
from datetime import datetime
from FileIO import read csv, write csv
# to print and process dates
# to read and write files
# tuple of valid positi
VALID POSITIONS =
('C', '1B', '2B', 'SS', 'LF', 'CF', 'RF', 'P')
main
':
# main driver function
if
name
data = read csv()
now = datetime.now()
# fetch the csv file data using read csv function
# store the current date, month and year
# printing to the display
print ("=" *60)
string = "Basketball Team Manager"|
print (string.rjust (len (string) + 20, " "))
# print the current date
print ("CURRENT DATE: ", end="")
print (now.strftime("%Y-%m-%d"))
# get the game data
print ("GAME DATE: "
input_ = input ()
if input :
date = list (map(int, input .split("-")))
date of match = datetime(date[0], date[1]], date[2]).
print ("DAYS UNTIL GAME: ", end="")
print ((date of match - now).days)
end="")
# if the game data value was inputted
# convert input to list of ints. eg: 2020
# print the difference in data
# print the menu
print ("\NMENU OPTIONS\n" +
Display lineup" + "\n"
"2
"1
Add player" + "\n" +
"3
Remove player" + "\n" +
Move player" + "\n" +
Edit player position" + "\n" +
"6
"4
"5
Edit player stats" + "\n" +
"7 - Exit program\n")
print (", ".join (VALID_POSITIONS))
print ("=" * 60)
while True:
# infinite loop until user enters the value 7
option = input ("\nMenu option: ")
if option == "1":
# print the elements with padding
print (" " * 3 + f"{'Player'.ljust(31)}{'POS'.ljust(6)}{'AB'.ljust (6)}{'H'.ljust(6;
print ("=" *60)
for idx, data in enumerate (data, 1):
# to print the player lineup
# get the data
number = str(idx)
name = data["name"]
position = data["position"]
at bats = data["at bats"]
hits = data["hits"]
avg = int (hits) / int (at_bats)
# calculate the average
# using rjust to add the necessary space paddings
number
number.ljust (3)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F10db7dd5-51b9-4abe-a748-6884ff91846b%2F372d3a9c-60e4-4290-b41c-31a5fed019b4%2Fouxqo8j_processed.jpeg&w=3840&q=75)
Transcribed Image Text:File Edit Format Run Options Window Help
from datetime import datetime
from FileIO import read csv, write csv
# to print and process dates
# to read and write files
# tuple of valid positi
VALID POSITIONS =
('C', '1B', '2B', 'SS', 'LF', 'CF', 'RF', 'P')
main
':
# main driver function
if
name
data = read csv()
now = datetime.now()
# fetch the csv file data using read csv function
# store the current date, month and year
# printing to the display
print ("=" *60)
string = "Basketball Team Manager"|
print (string.rjust (len (string) + 20, " "))
# print the current date
print ("CURRENT DATE: ", end="")
print (now.strftime("%Y-%m-%d"))
# get the game data
print ("GAME DATE: "
input_ = input ()
if input :
date = list (map(int, input .split("-")))
date of match = datetime(date[0], date[1]], date[2]).
print ("DAYS UNTIL GAME: ", end="")
print ((date of match - now).days)
end="")
# if the game data value was inputted
# convert input to list of ints. eg: 2020
# print the difference in data
# print the menu
print ("\NMENU OPTIONS\n" +
Display lineup" + "\n"
"2
"1
Add player" + "\n" +
"3
Remove player" + "\n" +
Move player" + "\n" +
Edit player position" + "\n" +
"6
"4
"5
Edit player stats" + "\n" +
"7 - Exit program\n")
print (", ".join (VALID_POSITIONS))
print ("=" * 60)
while True:
# infinite loop until user enters the value 7
option = input ("\nMenu option: ")
if option == "1":
# print the elements with padding
print (" " * 3 + f"{'Player'.ljust(31)}{'POS'.ljust(6)}{'AB'.ljust (6)}{'H'.ljust(6;
print ("=" *60)
for idx, data in enumerate (data, 1):
# to print the player lineup
# get the data
number = str(idx)
name = data["name"]
position = data["position"]
at bats = data["at bats"]
hits = data["hits"]
avg = int (hits) / int (at_bats)
# calculate the average
# using rjust to add the necessary space paddings
number
number.ljust (3)
![FilelO.py- C:/Users/lyart/OneDrive/Desktop/project2_AppDevelopment/FilelO.py (3.9.1)
File Edit Format Run Options Window Help
import csv
def read csv():
Function to read data from the players.csv file
data = []
# to store the data from the csv file
with open ('players.csv') as csv 'file:
# using context manager to open and close t
CVs reader = csv.reader(csy file)
for row in cvs reader:
{"name": row[0],
"position": row[1],
"at bats": row[2],
"hits": row[3] }
dictionary
# storing the data into a dictionary
data.append (dictionary)
# creating a list of dictionary objects
return data
# return data to the main program
def write csv(data):
Function to write data back to the players.csv file
with open('players.csv', 'w') as csv file:
writer = csv.writer(csv fi'e)
# using context manager to open and cl
for row in data:
writer.writerow(row.values(() )
# writing data to the file](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F10db7dd5-51b9-4abe-a748-6884ff91846b%2F372d3a9c-60e4-4290-b41c-31a5fed019b4%2Fm7dyr6_processed.jpeg&w=3840&q=75)
Transcribed Image Text:FilelO.py- C:/Users/lyart/OneDrive/Desktop/project2_AppDevelopment/FilelO.py (3.9.1)
File Edit Format Run Options Window Help
import csv
def read csv():
Function to read data from the players.csv file
data = []
# to store the data from the csv file
with open ('players.csv') as csv 'file:
# using context manager to open and close t
CVs reader = csv.reader(csy file)
for row in cvs reader:
{"name": row[0],
"position": row[1],
"at bats": row[2],
"hits": row[3] }
dictionary
# storing the data into a dictionary
data.append (dictionary)
# creating a list of dictionary objects
return data
# return data to the main program
def write csv(data):
Function to write data back to the players.csv file
with open('players.csv', 'w') as csv file:
writer = csv.writer(csv fi'e)
# using context manager to open and cl
for row in data:
writer.writerow(row.values(() )
# writing data to the file
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education