1

I am trying create a kivy python app which involves storing user input to a .txt file, but every time i add user input to the .txt file it always removes my old information. How can i stop this from happening or is there another easy and cost free alternative?

545
  • 11
  • 1
  • 1
    Does this answer your question? [How do you append to a file in Python?](https://stackoverflow.com/questions/4706499/how-do-you-append-to-a-file-in-python) – M. Martin Jun 03 '20 at 21:03

1 Answers1

0

You can use Json file. Developers recommend using JsonStore, saving to txt is somehow not very good. Plus it will be easier to use if you want to transfer your application to a mobile device

from kivy.storage.jsonstore import JsonStore

store = JsonStore('file name.json')

# put some values
store.put('tito', name='Mathieu', org='kivy')
store.put('tshirtman', name='Gabriel', age=27)

# using the same index key erases all previously added key-value pairs
store.put('tito', name='Mathieu', age=30)

# get a value using a index key and key
print('tito is', store.get('tito')['age'])

# or guess the key/entry for a part of the key
for item in store.find(name='Gabriel'):
    print('tshirtmans index key is', item[0])
    print('his key value pairs are', str(item[1]))

More information

Ne1zvestnyj
  • 1,391
  • 1
  • 7
  • 25