classes for fun and newbies
Bruce Dykes
bkd at graphnet.com
Wed Mar 20 06:26:54 EST 2002
Just to make sure I'm on the right track here...
I'm reading records from a file. This is a flat file, with one line per
record, and each line being some 380+ characters long, with about 40 fields
in each record.
Now I'm thinking that the easiest way to deal with these records (in
preparation for developing a Zope app to interface with them), is to set up
a class, with attributes for each field:
class call_record:
def __init__(self, record=''):
self.record_id=record[0:5]
self.date=record[6:11]
etc...
Now what I expect to be able to do is say:
log = readlines(today.log)
and then summon discrete bits of info like so:
print call_record.record_id(log[1])
However, all I get when I try this is the return of of the object attribute
instance and its memory address.
Am I on the right track and just overlooking something obvious? Is there
already an app that does something similar that I can browse for pointers?
On a side note, it was fun just cranking out a python script that created
the class code from the file documentation. 8-)
bkd
More information about the Python-list
mailing list