classes for fun and newbies

Bruce Dykes bkd at graphnet.com
Wed Mar 20 09:13:46 EST 2002


----- Original Message -----
From: "Gustavo Niemeyer" <niemeyer at conectiva.com>
To: <python-list at python.org>
Sent: Wednesday, March 20, 2002 07:10
Subject: Re: classes for fun and newbies


> > class call_record:
> >     def __init__(self, record=''):
> >         self.record_id=record[0:5]
> >         self.date=record[6:11]
> [...]
> > print call_record.record_id(log[1])
>
> Isn't it call_record(log[1]).record_id? If you're going to access
> many fields, you should probably save this instance in a temp variable
> (e.g. rec = call_record(log[1])) to avoid parsing it every time.

AHA! That should do it. I'll give it a go today. I'm glad my class code
seems to be okay. Now I have to add a pair of dictionaries to it...8-)

I'll likely be using no more than a half dozen as search/filter terms. But
that still means I'll have to read and search through the entire list at
least once. I'll have to define a search function in the code that can be
called as many times as necessary, and the temp variable will be local to
the function, simply returning a smaller dataset on each pass.

The only time I'll be interested in the total set  of fields is for display.

Thanks
And thanks to Emile and Tjabo, too...









More information about the Python-list mailing list