MACHARIAH Kuria
MACHARIAH Kuria

Reputation: 13

using inputs variables into csv file

iam trying to save user input under the csvcolumns as shown below, but each input is being saved in its own row. Example: if you input John under the name variable, its being saved as j o h n below is the code.

import time
import csv
csvcolumns= [ "NAME", "CAR MAKE", "YEAR OF MANUFACTURE", "IDENTIFICATION     NUMBER", "DATE"]
Name= input("Enter your name: ")
Car_make= input("Enter your car make e.g Toyota probox: ")
YOM= input("Enter the car YOM: ")
ID= input("Enter your identification number details: ")
todays_date= time.strftime("%Y-%m-%d %H:%M:%S")
with open('E:\doo.csv', 'w') as csvFile:
  writer=csv.writer(csvFile, delimiter=',')
  writer.writerow(csvcolumns)
  writer.writerows(zip(Name, Car_make,YOM,ID,todays_date))


print("writing completed")

Upvotes: 0

Views: 48

Answers (1)

Slam
Slam

Reputation: 8572

You're lost somewhere in complex things.

If all this data is single row, write it with

writer.writerow([Name, Car_make, YOM, ID, todays_date])

Upvotes: 2

Related Questions