I'm currently using pretty table for a Barbershop P.O.S implementation where the program needs to generate reports that an admin user can view. The reports are copied line by line from a csv(converted into a pretty table) each time a user logs that a service from the csv has been performed.
I'd like these lines to be written into a new report csv file, and be accessed by the admin through both the python interpreter and other file systems.
So far, the program copies the lines from the original csv (it's printing them out) but isn't writing them into the report log csv.
Does anyone know how to implement this?
Here's my code: Module that opens csv with Services and converts it into a table:
from prettytable import from_csv
def servicetable():
fp = open("Barbershop.csv", "r")
file = from_csv(fp)
fp.close()
print(file)
Function that copies the line and pastes it into log.csv
def log_service():
while True:
try:
response3 = input("Please choose service from list using the ServiceID.\n")
response3 = int(response3)
#copy service table into another table
fp = open("Barbershop.csv", "r")
file_copy = from_csv(fp) #filecopy is a variable that holds the table
fp.close()
x = file_copy[response3:(response3+1)] #copy this row of the table
print(x) #print it out as confirmation
y = open("log.csv", 'wb') #create and open another csv file
writer = csv.writer(y, delimiter=' ',quotechar='"',quoting= csv.QUOTE_NONE) #create writer object
writer.writerows(y) #write each iteration value of x into log.csv
choice2 = input("Continue yes/ no:").lower()
if not(choice2=="yes" or choice2=="y"):
break
except ValueError:
print("Please enter valid ID")
Of course, a simpler or more efficient implementation of the concept is also welcome. As always, many thanks!