Using Pretty Table In Python to copy row from a table and write it into a csv file -


i'm using pretty table barbershop p.o.s implementation program needs generate reports admin user can view. reports copied line line csv(converted pretty table) each time user logs service csv has been performed.

i'd these lines written new report csv file, , accessed admin through both python interpreter , other file systems.

so far, program copies lines original csv (it's printing them out) isn't writing them report log csv.

does know how implement this?

here's code: module opens csv services , converts table:

from prettytable import from_csv  def servicetable():     fp = open("barbershop.csv", "r")     file = from_csv(fp)     fp.close()     print(file) 

function copies line , pastes log.csv

def log_service():     while true:       try:         response3 = input("please choose service list using serviceid.\n")         response3 = int(response3)          #copy service table table         fp = open("barbershop.csv", "r")         file_copy = from_csv(fp)   #filecopy variable holds table         fp.close()         x = file_copy[response3:(response3+1)]  #copy row of table         print(x)                                #print out confirmation          y = open("log.csv", 'wb') #create , open csv file         writer = csv.writer(y, delimiter='  ',quotechar='"',quoting= csv.quote_none) #create writer object         writer.writerows(y) #write each iteration value of x 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, simpler or more efficient implementation of concept welcome. always, many thanks!


Comments