Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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 March 19th, 2004, 09:33 PM
Phreakster001 Phreakster001 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 Phreakster001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Phreakster001
Question Saving Preferences

Hello fellow Python programmers! Im a newbie that just joined. Anyways I need help. Im making a text editor program. The first problem Ive had so far is saving/getting the prefferences. How could I do that? Like maybe I have stuff like HTML tag colors for santax highlighting, and if they want to view line numbers just for a few examples. If anyone could please lead me in the right direction it would be greatly appreciated.

BTW: I just started learning Python and its awesome! way better than C++, or C# combined! Im glad my friend told me about it. I just wish it was a little more popular so it would be easier to find support and stuff for it.

Reply With Quote
  #2  
Old March 20th, 2004, 02:48 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,585 DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level)DevCoach User rank is General 6th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 2 h 58 m 23 sec
Reputation Power: 1372
Do you want the options file to be editable by the user?

If so then take a look at the ConfigParser module in the standard library. This lets you read config files in a similar format to Windows .ini files, e.g.

Code:
[SectionName]
key = value
#or
key: value


However the module does not handle writing out the config file - you have to do that yourself.

If you are not concerned about having the config editable by the user, then I would use the pickle module. Create an object to hold all the options - this could be a dictionary or a class. Then save and load it like this:

Code:
import pickle   #(or import cPickle as pickle, which is faster)

def saveOptions(options, filename):
    pickle.dump(options, file(filename, 'wb'), -1)

def loadOptions(options, filename):
    return pickle.load(file(filename, 'rb'))


Regards,

Dave - The Developers' Coach

Reply With Quote
  #3  
Old March 20th, 2004, 05:25 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: 12
Send a message via MSN to Grim Archon
Like DevCoach says, pickle is the normal way to save data.
It just so happens my ptypes module here provides dictionaries and lists with built in pickleing.

The nice thing about it is you can use them as normal and when you want to save the data you just call their Save() method.

I know some people already have ptypes, the 0.3 version is a big update.

Grim
__________________
*** Experimental Python Markup CGI V2 ***

Reply With Quote
  #4  
Old March 20th, 2004, 04:12 PM
Phreakster001 Phreakster001 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 Phreakster001 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to Phreakster001
Quote:
Originally Posted by DevCoach
Do you want the options file to be editable by the user?

If so then take a look at the ConfigParser module in the standard library. This lets you read config files in a similar format to Windows .ini files, e.g.

Code:
[SectionName]
key = value
#or
key: value


However the module does not handle writing out the config file - you have to do that yourself.

If you are not concerned about having the config editable by the user, then I would use the pickle module. Create an object to hold all the options - this could be a dictionary or a class. Then save and load it like this:

Code:
import pickle   #(or import cPickle as pickle, which is faster)

def saveOptions(options, filename):
    pickle.dump(options, file(filename, 'wb'), -1)

def loadOptions(options, filename):
    return pickle.load(file(filename, 'rb'))


Regards,

Dave - The Developers' Coach

Ok thanks. I don't care if the user edits it so Ill go with the ConfigParser but I need a good tutorial on it or at least a source code to reference. Best regards !

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Saving Preferences

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap