I'm developing a piano learning software. For that I need save details of profiles registered by the user. Now I'm using python file handling but there are some issues. So what should I do to use XML or Qstring files.Suppose I've to save user_name(string),lesson_id(integer) for each profile.
-
why not storing user profiles in database ? – NotCamelCase Apr 08 '12 at 14:24
-
what ever.Then how can I do that? I just wanted to store details , thats all – Hemanth Raveendran Apr 08 '12 at 16:16
1 Answers
You have multiple options for how to solve this. The biggest factor in determining which one to use depends on how you will need to access this data. You shouldn't need to go to general formats like XML if this data is only intended for internal use of your app.
Database
Because you are writing a piano application in Qt, the only database solution I think that would be appropriate would be sqlite3. PyQt has the QtSql module for this functionality. See QSqlDatabase. This could be used with sqlite3, which is portable and embedded. This method can be overkill if you don't need to do queries. If all you need to do is pull up a saved profile document, then see other methods. This database approach would inflate the size of your packaged application a little.
I normally use QSettings to save state information about the interface (size, position, last settings of various widgets), but you can save anything you want. It automatically uses the appropriate user location and format for the current platform.
Simple pickling
If you just want to use an approach where you save out a profile file manually, you can just pickle your profile data using cPickle
import cPickle
data = {'user_name': 'foo', 'lesson_id': 5}
with open('/path/to/profile.file', 'wb') as profile:
cPickle.dump(data, profile)
If you do need a human readable format, you could just as easily use json here:
import json
data = {'user_name': 'foo', 'lesson_id': 5}
with open('/path/to/profile.file', 'wb') as profile:
json.dump(data, profile)
My personal recommendation in this case would be to use QSettings. Its automatically user-based, and meant for storing profile data.

- 90,542
- 19
- 167
- 203
-
You can use XML for storing and accessing the user profile database. For using XML for storing the user profile database you need to use lxml, element tree modules. Create the xml template and store the user profiles. – Prince Dhadwal Oct 03 '17 at 11:39