python 3.x - Python3 Shelve: how to append a value permanently? -


i want users append new values in shelve module. everytime close file, appended values disappear.

import shelve   shelvepracticefile = shelve.open('/shelvepractice', writeback=true)  shelvepracticefile['funnynames'] = ['lala', 'dada', 'mama', 'baba'] shelvepracticefile['funnynumbers'] = [3,9,18] shelvepracticefile['funnyskills'] = ['python', 'football', 'gaming']  # try append.  print('lets try append. type in something') myinput = input()  shelvepracticefile['funnyskills'].append(myinput)  # lets read , print shelve file we've created!  print(shelvepracticefile['funnynames']) print(shelvepracticefile['funnynumbers']) print(shelvepracticefile['funnyskills'])   shelvepracticefile.close() 

this code works , saves shelve. beginners me; if keep running code above on , over, shelvepracticefile['funnyskills'] = ['python', 'football', 'gaming'] part rewrite dictionary , remove value have appended.

i hope helps other people doing same mistake :)


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -