August 10th, 2004, 01:04 AM
is there a way to make a program that when u run it it will save youre variables?
When u close it then reopen it youre variables would still be the same.
August 10th, 2004, 02:44 AM
you've got a few options. you can store them in a plain text file and devise some algorithm for loading them into your program correctly, you could use the shelve module to store them as a kind of persistent dictionary, or you store them in a file with the pickle module. there's a few different avenues to explore, check out http://docs.python.org/modindex.html for info on the pickle and shelve modules.
August 10th, 2004, 03:16 AM
If you want a pre-packaged solution you could try my ptypes module. It provides a persistent dictionary and list.
There is a link for more info on how it works and it is self documented.
August 10th, 2004, 08:01 AM
why use a third party module to create a persistent dictionary when that's exactly what the shelve module does? what other advantages does it offer? I see you can store a list too, but that's easy to do with the shelve module. ie
db = shelve.open('test.dbm')
db['list_obj'] = [1, 2, 3]
August 10th, 2004, 12:27 PM
It's just one more option to consider
I like the idea of a datatype that can save/reload itself.
seems tidy to me and follows in the spirit of:
my_programs_configuration = ptypes.pdict("my_prog")
my_programs_configuration['window_size'] = "100x200"
August 10th, 2004, 07:01 PM
August 11th, 2004, 11:23 PM
i like this idea the most. It suites my needs the best.
Originally Posted by rebbit
But just a simple noob question- What is the dbm on test.dbm?
also- if test.dbm is made for shelves, will it create the test.dbm if it is not already made?
August 12th, 2004, 06:38 AM
DBM stands for DataBase Manager, and yes if the file does not already exist it will be created.
August 12th, 2004, 06:16 PM
thx alot this helps a bunch.
but... i have a questions
when i try to open test.dbm theres nothing in it, is that normal?(i have put a few things in it)
August 12th, 2004, 07:06 PM
there should be data in it, yes, but nothing that makes any sense to read. what editor are you opening it with? but anyway, so long as you can save data to it and then read the data back again it's fine.
August 13th, 2004, 09:44 PM