Storing user data in a Python script

前端 未结 4 1757
伪装坚强ぢ
伪装坚强ぢ 2020-12-15 13:33

What is the preferred/ usual way of storing data that is entered by the user when running a Python script, if I need the data again the next time the script runs?

Fo

4条回答
  •  独厮守ぢ
    2020-12-15 14:13

    you could use a slite database or a CSV file. They are both very easy to work with but lend themselves to rows with the same type of information.

    The best option might be shelve module

    import shelve
    
    shelf = shelve.open(filename)
    shelf['key1'] = value1
    shelf['key2'] = value2
    
    shelf.close()
     # next run
    shelf.open(filename)
    
    value1 = shelf['key1']
    #etc
    

提交回复
热议问题