|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
||||
|
||||
|
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 *** |
|
#4
|
|||
|
|||
|
Quote:
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 ! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Saving Preferences |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|