+ 1
Run a file,input the data and save the current file automatically. How to code this ?
#if I input 5 to the variable x then print(data) = [0, 5, 10] #Now I want to replace [0, 10] by [0, 5 ,10] #And this file should be automatically saved #When I reopen the file data should = [0, 5, 10] #before giving any new input to the data data = [0,10] x = int(input()) if x in data: print(str(x) + "is in data") else: data.insert(1, x)
1 Respuesta
+ 1
You can use the pickle module to save a python object (such as a list) to a file.
https://www.google.com/amp/s/www.geeksforgeeks.org/understanding-python-pickling-example/amp/