converting tcl database file to python

Bob van der Poel bvdpoel at uniserve.com
Sat Jul 15 22:42:36 EDT 2000


Bob Schmertz wrote:
> 
> Bob van der Poel wrote:
> 
> > 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 *CDItem[];
> >         }CDENTRY;
> >
> >         CDENTRY Mydata[maxtitles];
> >
> > Or something like that. Any suggestions on how that would translate to a
> > proper python idiom?
> >
> 
> Did you consider a CdItem class?

No. I've looked at them but the one thing  that bothered me is that
after defining a class (aka structure) one is free to add variables a
will.

> class CDITEM():
>     def __init__(self, name, comment, etc):
>         self.name = name
>         self.comment = comment
>         self.etc = etc
> 
> mydata = []
> mydata.append(CDITEM("Thriller", "gift from my mom", "more stuff"))

For example, after the above I can write:

	mydata.dummy="bad data"

but, since it's just as hard to access the 'dummy' I guess it's not a
big deal. Just used to C too much I guess.

Looks like a class is the way to go.
 
> > 2. Any quick ideas on how to convert the tcl-style data file to
> > something python can deal with?
> 
> Tcl's probably what I'd go with for this.  Haven't dealt with it for a while,
> though.

Yes. started a bit this PM. I think that what I'll do is write a
conversion in tcl and end up with a very-verbose datafile format. With
PentiumIIs who cares about a few extra cycles of overhead parsing a
file. I've just gotta get into the 21th century.

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



More information about the Python-list mailing list