0

so what I've been trying to do is store data on a program so that way when I reopen my python program so all the previous data is still there. what I want to do is have the ability to use an input statement and allow the user to add data and then have it be saved. I want it to be saved if its numbers or words so if anyone has any suggestions or ideas to give me on how to do this please let me know or point me in the right direction please let me know.

list = [1, 2, 3, 4]
bon = str(next(reversed(list)))
print(bon)
a = input("new: ")
if a == 'new':
  bag = bon + 1

2 Answers2

1

You will need some time of database or storage. There are a few ways to do this.

  1. You can create a CSV file (or a flat file with a custom delimiter). Each time your program is opened read from the CSV file and put the data in a list. Vice-versa you can just write new lines and save the file when new data is added. Although this is simple to begin with it can get even more complicated it you wish to do things like update data later on.
  2. You can use a database. The easiest one to get started with is sqlite which creates a local DB file and doesn't need database software.
  3. You can go further and use something like pickle but I can't see this being useful or the best use of your time in this case.
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Oddity
  • 480
  • 2
  • 12
0

I would start with taking a look at :

  • Flat files for data storage

  • SQL to improve access to persistent data

  • SQLite for data storage

  • SQLAlchemy to work with data as Python objects

There's a pretty good article here https://realpython.com/python-sqlite-sqlalchemy/ that explains how to achieve that in Python.

richetechguy
  • 38
  • 1
  • 5