Python4Kids: New Tutorial - An Awful Pickle

 

Python4Kids: New Tutorial - An Awful Pickle
Feb 7, 2011, 07 :02 UTC (0 Talkback[s]) (1511 reads)
(Other stories by Brendan Scott)

[ Thanks to Brendan Scott for this link. ]

"So, we know how to save trivia questions to a file, and how to read them back from a file in the future. Moreover, we have decided on a particular way of structuring the data which makes a question. That is, the question is followed by the correct answer and then a number of incorrect answers. Now we have to translate between a list (which has a concept of elements), and a file (which doesn?t). Files are ?flat? ? which is to say that they have no sense of structure, they are simply a stream of data. A file may record all of the characters which are the questions and answers, but it wouldn?t record the fact that they are a list or, indeed, that they are any kind of Python object. I was originally just going to run with this to let you find out about files, but I have instead decided to introduce a further concept ? the Python pickle!

"pickle is a module which allows you to store Python objects including their structure. That means after you have pickled an object to a file, you can later load that object back up from the file and all the structure associated with that object will be preserved."

Complete Story

Related Stories:
Python for Newbies(Jan 28, 2011)
Testing Tools and Techniques in Python(Dec 25, 2010)
Animating Graphic Objects using Python(Dec 09, 2010)
Python Graphics: Animation Principles(Dec 07, 2010)
Python Graphics: Combining Raster and Vector Pictures(Dec 03, 2010)


View the original article here

0 comments: