Python Forum
Changing the content of the table and saving the new data into another file
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing the content of the table and saving the new data into another file
#1
Hi,

I am currently using a CSV file (actually one big table of data) consisting of data including names, addresses and coordinates of various restaurants.

I want to write a code that allows the users to introduce more than one restaurant (like in the code below), and allows him to stop when they want, by asking “do you want to input one more restaurant? (y/n)”. By answering “n”, the process should stop and the file is saved.

The code I now have is:
name = input("restaurant name is: ")
address = input("restaurant address is: ")
lonlat = input("coordinates are: ")
new_row = list((name, address, lonlat))

table.append(new_row)
print(table[-1])

with open("GermanRestaurants_v1.csv", mode="w") as handler:
    file_writer = csv.writer(handler)
    for row in table:
        file_writer.writerow(row)
However, I don't now how/where to include a defined questioned where the first part of the code is repeated when someone answers yes, or the file will be saved when someone answers no.

Hope someone can help me out. Thankss.
Reply
#2
name = input("restaurant name is: ")
address = input("restaurant address is: ")
lonlat = input("coordinates are: ")
new_row = list((name, address, lonlat))
table.append(new_row)
print(table[-1])
with open("GermanRestaurants_v1.csv", mode="w") as handler:
file_writer = csv.writer(handler)
for row in table:
file_writer.writerow(row)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating Data Set for Changing Oscillation Motion jcraw77 1 1,884 Jun-19-2020, 03:41 AM
Last Post: ndc85430
  Saving to Json file Shambob1874 1 2,434 May-30-2018, 10:00 PM
Last Post: micseydel
  Login Module Help - Comparing data in a text file to data held in a variable KeziaKar 0 2,223 Mar-08-2018, 11:41 AM
Last Post: KeziaKar
  file a table of values Ybivashka322 4 3,671 Dec-14-2017, 06:11 PM
Last Post: mpd
  Saving the results from an input in a txt. file pythonenthusiast 2 2,646 Nov-28-2017, 03:52 PM
Last Post: wavic
  Presenting data from a dictionary in a basic table ijosefson 3 3,278 Oct-16-2017, 04:13 AM
Last Post: Larz60+
  Saving an numpy.ndarray as .ply file in python Tina 4 16,986 Oct-11-2017, 06:08 PM
Last Post: Tina

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020