converting tcl database file to python

Bob van der Poel bvdpoel at uniserve.com
Sat Jul 15 19:31:33 EDT 2000


I'd like to convert a program I have from tcl/tk to python/tkinter (I
just can't read the tcl stuff anymore!). The biggest initial problem I
have is converting the data from a tcl fromat to something python will
be happy with.

What I have is a database of my CD collection. The flat text file I'm
using for storage is read into a tcl list. Each line looks something
like:

	{#1 Million Sellers} {} Laurie Rock {} {Chapel of Love} {Dixie Cups} {}
{} ....

Tcl reads this and parses off the fields into the CDname, Comment,
Label, Catagory and then takes the remainder as 4 field entries for the
Title, Artist, Composer, and Timing. The 4 field groups continue to the
EOL.

So, 2 questions:

1. What would be a suitable python datatype to store the data? I'm
thinking that I could have a dictionary with the CD name as the key and
then have a bunch of lists associated with each dictionary entry. I'm
also thinking that this is dumb. If I were using C I'd use a structure
like this:

	typedef struct{
		char *Title, *Artist, *Composer, *Timing;
	}CDITEM;
	typedef struct{
		char *Name;
		char *Comment;
		char *Label;
		char *Catagory;
		char *CDItem[];
	}CDENTRY;

	CDENTRY Mydata[maxtitles];

Or something like that. Any suggestions on how that would translate to a
proper python idiom?

Maybe I should can the idea of having in-memory data and convert this
sucker to use a proper database idiom? Is there a reference/tutorial
document for gdbm somewhere?

2. Any quick ideas on how to convert the tcl-style data file to
something python can deal with? The initial problem is that some items
in the file are {} delimited and others are simply space delimited
(single words). I suppose the simpliest might be to write a tcl program
to read the stuff and then rewrite it to something resembling whatever
my new data format is going to be.

Thanks.


-- 
   __
  /  )      /         Bob van der Poel
 /--<  ____/__        bvdpoel at uniserve.com
/___/_(_) /_)         http://users.uniserve.com/~bvdpoel




More information about the Python-list mailing list