Stuck newbie
Diez B. Roggisch
deets_noospaam at web.de
Tue Dec 2 17:36:01 EST 2003
> 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)?
First, you could assign records[-1] to a variable, like this
foo = records[-1]
print foo.flags, foo.list1, foo.list2
Another way would be to implement __repr__ on record:
class record:
.... # the old stuff
__repr__(self):
return repr((self.flags, self.list1, self.list2))
Then
print records[-1]
The __repr__ method is automagically called when print is used on an object.
Diez
More information about the Python-list
mailing list