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

boB Stepp robertvstepp at gmail.com
Wed Oct 8 19:51:08 CEST 2014


On Wed, Oct 8, 2014 at 11:27 AM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> 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.

Ah! Thanks. That should work well.

> 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 am not seeing JSON listed among python's standard libraries for
version 2.4.4. Is this something that has to be independently
installed?

>> 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?

Compare the current library index,
https://docs.python.org/2/library/index.html, with the 2.4.4 one,
https://docs.python.org/release/2.4.4/lib/lib.html . On the former I
was able to immediately find the csv module with a quick scroll, but
in the latter I found myself using my browser's find function to
locate the link. The other improvement that the newer presentation has
that the older does not, is an actual brief example along with the
description in the module contents. Perhaps these are minor points...


-- 
boB


More information about the Tutor mailing list