Stuck newbie

r.e.s. r.s at XXmindspring.com
Tue Dec 2 22:04:13 CET 2003


"Diez B. Roggisch" <deets_noospaam at web.de> wrote ...

> The last approach would be to create a class new_record:
> 
> class new_record:
>   def __init__(self):
>     self.flags = 0
>     self.list1 = []
>     self.list2 = []

[another beginner here]

Suppose I do the above, followed by this:

records = []
rec = new_record()
rec.flags = 1
rec.list1 = [10]
rec.list2 = ['a']
records.append(rec)
print records
# [<Script1.new_record instance at 0x00BCBDA0>]
print records[-1]
# <Script1.new_record instance at 0x00BCBDA0>
print records[-1].flags, records[-1].list1, records[-1].list2
# 1 [10] ['a']

Is there a simpler way to accomplish the last line
(as I expected the simplest "print records" to do)?

Thanks.
--
r.e.s.




More information about the Python-list mailing list