Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

My Quickly app requires data files to store settings, configuration and etc. How would I do this inside the app folder. Keep in mind that I will need to read and write to these files while the app is running on a client's computer. Thanks.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

This has more to do with general application development than Quickly. Have a look at your home folder and press ctrl+h or the equivalent to show hidden files in your file manager.

Applications who need to store usersettings do this by creating a hidden folder (prefixed with a dot) and write the configuration files there. Other stuff like a database, extra plugins etc can be put here too.

This has to be done in the code at runtime, not during installion. Something like this should be enough:

import os
confdir = os.path.join(os.path.expanduser('~'), '.myapp')
conffile = os.path.join(confdir, 'myapp.conf')
if not os.path.exists(confdir):
    os.makedirs(confdir)
    with open(conffile, 'w') as f:
        f.write('This is the default config')

Have a look at the ConfigParser or JSON module to work with a configuration format.

share|improve this answer
    
Two questions. How would I write to this file and read from it? Why do you not check if the conffile exists? –  njallam Jun 26 '12 at 17:15
    
Reading and writing is just standard Python: docs.python.org/tutorial/… –  Timo Jun 26 '12 at 20:55
    
If the confdir doesn't exist yet, then the conffile won't either. If the confdir does exist, your program already created a conffile. You could do some extra checks etc, this is just a basic example. –  Timo Jun 26 '12 at 20:58
    
OK, now what I don't understand is how to make that os.path thing work with standard python open() –  njallam Jun 27 '12 at 6:26
    
I edited my answer with some more details. This is just very simple Python though, maybe it's not a bad idea to read the tutorial first. docs.python.org/tutorial/index.html –  Timo Jun 27 '12 at 9:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.