[Tutor] Saving information for my program

James Reynolds eire1130 at gmail.com
Mon Mar 21 16:30:49 CET 2011


On Mon, Mar 21, 2011 at 11:11 AM, michael scott <jigenbakuda at yahoo.com>wrote:

> I apologize now but I'm going to be spamming  the tutor list as I have just
> decided to create an extremely ambitious project for someone of my level.
> Anyhow, I will start with my first question.
>
> How do I save user created information in python?
>
> In my progam I will have users input various "attributes" of people they
> like (age, height, movies they have been in, songs they sung in, favorite
> part of them,  important links dealing with them, etc), and I'd like to know
> how to save these things so that even after you stop running the program
> they are saved and when you start the program again, these variables are
> loaded. This part of my program will be sort of like an
> offline-wiki-gui-thingie.
>
> I was planning on using classes for each person so that I could store their
> attributes that way .
> jessica = Profile()
> jessica.name = "jessica ngorn"
> jessica.age = 25
> jessica.favorite_song = "chinpo no  uta"
>
> I was thinking I have 2 options, which is save the information to a text
> file a write / read it in every session, but I have no idea how to do this
> with class attributes. I know how to do it for like a paragraph of text, but
> I have no idea how to do it with classes and their attributes.
>
> The other option I was thinking about was using the pickle module. I have
> never used it, but I read the documentation, and I'm not exactly sure how to
> use it... it says it only saves the class "name", but not the body (same for
> functions), but how would that help me?
>
> Well if you can contribute to helping me please do. Linking me to stuff to
> read is great, explaining it here is great, writing short example code is
> great too, anything helps.
> ----
> What is it about you... that intrigues me so?
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>







This would probably be a good opportunity for you to learn about SQL and
specifically SQlite3, which comes with current versions of Python. For what
you are describing, you could probably have a single table in a database
handle all of this. For it to populate immediately, have your program call
in its __init__ whatever program you have to extract all the data from the
database, then create all of  your Profile objects.

I think if you just read up on SQlite3 and what it can do, or SQL more
generally, you will have an Aha! moment on your own.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110321/9ef5d57a/attachment.html>


More information about the Tutor mailing list