How-to create a Pascal Record using Python

Steve Holden sholden at holdenweb.com
Thu Jan 4 16:14:28 EST 2001


Daniel <Daniel.Kinnaer at AdValvas.be> wrote in message
news:3a54e0c0.21998314 at news.skynet.be...
> On Thu, 4 Jan 2001 14:21:27 -0500, "Steve Holden"
> <sholden at holdenweb.com> wrote:
>
>
> >
> >    return file.read().splitlines()
> >
> >
> >regards
> > Steve
> >
> Thanks for your reply.  Was it correct to handle Pascal-like records
> the way I did, or is there a more Python-ly manner of handling this?
>
> Suppose I have something like
>
> TMyRecord = record
>      aName : string;
>      adate   :  TDateTime;
>     aZIP     : integer;
>   end; file://record
>
> var MyRecs : array [1..100] of TMyRecord;
>       f             : file of TMyRecord;
>
> How is this handled in Python?  Sorry for these questions, but I
> really would like to learn about all of this.
>
> Thanks
>
It's so long ango since I gave up using Pascal I'm not sure how the data
will be stored on the disk.  That's the crux of your question, I suspect.

Assuming a textual representation similar to the one in your original post,
and further assuming that the strings don't contain commas (always dubious
about such assumptions, but you asked), then once you've got the lines in
your program you could use string.split() or the split() method which 2.0
introduced for strings to separate out the chunks between the commas.

If the records are written to disk in binary (and I doubt this, since the
strings are apparently of arbitrary length, so how is their length encoded)
then the struct module contains features you can use.

Someone who's using both languages may give you better advice.  For now,
don't worry _too_ much about Pythonicity, just build something that works.
You can always improve it later!

regards
 Steve







More information about the Python-list mailing list