Python Forum
How do I permanently change a list after user's input?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I permanently change a list after user's input?
#6
(Oct-31-2018, 12:47 PM)Ablazesphere Wrote: Please show me if you have any idea to update a program permanently.
You need to use a module for data persistence. There are the pickle module or the json module in the standard library, but you can also use third party modules such as tinydb
from tinydb import TinyDB, Query
record = Query()
db = TinyDB('db.json')
if db.search(record.name == 'lst'):
    lst = db.search(record.name == 'lst')[0]['value']
else:
    lst = ["Laptop", "Phone", "Python"]
    db.insert({'name': 'lst', 'value': lst})
user = input("Enter an element : ")
lst.append(user)
db.update({'value': lst}, record.name == 'lst')
Reply


Messages In This Thread
RE: How do I permanently change a list after user's input? - by Gribouillis - Oct-31-2018, 04:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  difference between forms of input a list to function akbarza 6 1,037 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  WHILE LOOP NOT RETURNING USER INPUT AFTER ZerroDivisionError! HELP! ayodele_martins1 7 1,071 Oct-01-2023, 07:36 PM
Last Post: ayodele_martins1
  save values permanently in python (perhaps not in a text file)? flash77 8 1,237 Jul-07-2023, 05:44 PM
Last Post: flash77
  Change font in a list or tuple apffal 4 2,694 Jun-16-2023, 02:55 AM
Last Post: schriftartenio
  restrict user input to numerical values MCL169 2 918 Apr-08-2023, 05:40 PM
Last Post: MCL169
  user input values into list of lists tauros73 3 1,075 Dec-29-2022, 05:54 PM
Last Post: deanhystad
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,096 Dec-25-2022, 03:00 PM
Last Post: askfriends
Question Take user input and split files using 7z in python askfriends 2 1,105 Dec-11-2022, 07:39 PM
Last Post: snippsat
Sad how to validate user input from database johnconar 3 1,928 Sep-11-2022, 12:36 PM
Last Post: ndc85430
  How to change the datatype of list elements? mHosseinDS86 9 2,002 Aug-24-2022, 05:26 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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