Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 10th, 2004, 02:04 AM
evilbeefcake evilbeefcake is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 58 evilbeefcake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 21 m 45 sec
Reputation Power: 5
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.

Reply With Quote
  #2  
Old August 10th, 2004, 03:44 AM
rebbit rebbit is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 84 rebbit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 7 m
Reputation Power: 5
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.

Reply With Quote
  #3  
Old August 10th, 2004, 04:16 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 8
Send a message via MSN to Grim Archon
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 ***

Reply With Quote
  #4  
Old August 10th, 2004, 09:01 AM
rebbit rebbit is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 84 rebbit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 7 m
Reputation Power: 5
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()

Reply With Quote
  #5  
Old August 10th, 2004, 01:27 PM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 8
Send a message via MSN to Grim Archon
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() 
seems tidy to me and follows in the spirit of:
my_list.sort()
my_string.replace("*","+")

grim

Reply With Quote
  #6  
Old August 10th, 2004, 08:01 PM
rebbit rebbit is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 84 rebbit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 7 m
Reputation Power: 5
fair enough

Reply With Quote
  #7  
Old August 12th, 2004, 12:23 AM
evilbeefcake evilbeefcake is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 58 evilbeefcake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 21 m 45 sec
Reputation Power: 5
Quote:
Originally Posted by rebbit
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()


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?

Reply With Quote
  #8  
Old August 12th, 2004, 07:38 AM
rebbit rebbit is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 84 rebbit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 7 m
Reputation Power: 5
DBM stands for DataBase Manager, and yes if the file does not already exist it will be created.

Reply With Quote
  #9  
Old August 12th, 2004, 07:16 PM
evilbeefcake evilbeefcake is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 58 evilbeefcake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 21 m 45 sec
Reputation Power: 5
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)

Reply With Quote
  #10  
Old August 12th, 2004, 08:06 PM
rebbit rebbit is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 84 rebbit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 7 m
Reputation Power: 5
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.

Reply With Quote
  #11  
Old August 13th, 2004, 10:44 PM
evilbeefcake evilbeefcake is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 58 evilbeefcake User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 21 m 45 sec
Reputation Power: 5
thx alot it helped out.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > saving...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT