|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
saving...
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. |
|
#2
|
|||
|
|||
|
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.
|
|
#3
|
||||
|
||||
|
If you want a pre-packaged solution you could try my ptypes module. It provides a persistent dictionary and list.
http://www.peck.org.uk/p/python/ There is a link for more info on how it works and it is self documented. grim ![]()
__________________
*** Experimental Python Markup CGI V2 *** |
|
#4
|
|||
|
|||
|
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
Code:
import shelve
db = shelve.open('test.dbm')
db['list_obj'] = [1, 2, 3]
db.close()
|
|
#5
|
||||
|
||||
|
It's just one more option to consider
![]() I like the idea of a datatype that can save/reload itself. Code:
my_programs_configuration = ptypes.pdict("my_prog")
....
my_programs_configuration['window_size'] = "100x200"
......
my_programs_configuration.save()
my_list.sort() my_string.replace("*","+") grim |
|
#6
|
|||
|
|||
|
fair enough
![]() |
|
#7
|
|||
|
|||
|
Quote:
i like this idea the most. It suites my needs the best. 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? |
|
#8
|
|||
|
|||
|
DBM stands for DataBase Manager, and yes if the file does not already exist it will be created.
|
|
#9
|
|||
|
|||
|
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) |
|
#10
|
|||
|
|||
|
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.
|
|
#11
|
|||
|
|||
|
thx alot it helped out.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > saving... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|