0

For some reason unknown to me, this code is not actually creating a csv file, just a standard, generic file. I don't know why, so I would appreciate some help to change the code so it actually makes csv files. I'm new to coding, so apologies for poor code quality and stuff like that. For context, this program will allow data from weather drones to be saved to csv files.

Here is the code:

import csv

def filecreator():
    print("----------INPUT--DATA----------")
    filename = input("File Name: ")
    print("A file has been created named",filename,". csv")
    print("-------------------------------")




    with open(filename, 'w', newline='') as csvfile:
        w = csv.writer(csvfile, delimiter=' ')
        save = "y"
        while save == "y":
            drone = int(input("Drone Number: "))
            time = int(input("Time: "))
            temperature = input("Enter temperature: ")  
            windspeed = input("Enter windspeed: ")
            


            save = input("Would you like to save? Y/N: ")  
            if save.lower() == "y":
                w.writerow([drone, time, temperature, windspeed])   
                print("---Your data has been saved---")


        print("Program closed.")


userinput = input("Enter I to input data, V to view data or C to do calculations: ")

if userinput=="I" or "i":
    print("\nYou have chosen to input weather data to the program")
    filecreator()

elif userinput=="V" or "v":
    print("\nYou have chosen to view weather data.")

elif userinput=="C" or "c":
    print("\nYou have chosen to perform calculations with weather data.")





Jonesy19
  • 63
  • 1
  • 5

1 Answers1

2

You set the delimiter to ' ' you need:

w = csv.writer(csvfile, delimiter=',')
JeffUK
  • 4,107
  • 2
  • 20
  • 34