[Tutor] How best to structure a plain text data file for use in program(s) and later updating with new data?

Alan Gauld alan.gauld at btinternet.com
Wed Oct 8 18:27:23 CEST 2014


On 08/10/14 16:47, boB Stepp wrote:

>> It looks like you have csv like data.  Except you have a semicolon as
>> a separator.  Look at the csv module.  That should work for you
>>
> Joel, will the labels (like SERIAL_ROI:) cause me difficulties? I will
> need to strip these off to get to the actual data. But when I
> implement a data editor later, these labels will be needed (I think.).

You will get the name:value fields as strings.
You can then use string.split(':') to separate them and
then either lose the label or convert them to a dictionary.

If its not too big a task you could even convert the data
structure to JSON which is quite a close match to what you
have now and the json module will help you read/write
to them.

> I just now have located the documentation for python 2.4.4. It does
> not seem to be as friendly or easy to read as for the current version
> documentation.

Shouldn't be that much different.
What kind of anomalies are you seeing?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list