[Tutor] subclass of list
Bob Gailer
ramrom@earthling.net
Fri Jan 3 22:15:01 2003
--=======7F796E11=======
Content-Type: text/plain; x-avg-checked=avg-ok-1CF2B71; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit
Your reference to UserList helped. One thing I missed was that the internal
list can be set by passing a list as the argument to the instantiation call.
>>> class UL(UserList):pass
>>> ul=UL([1,2,3])
>>> ul
[1,2,3]
>>> ul.data
[1,2,3]
AND (using list instead of UserList)
>>> class UL(llist):pass
>>> ul=UL([1,2,3])
>>> ul
[1,2,3]
HOWEVER:
>>> ul.data
AttributeError: 'UL' object has no attribute 'data'
A little "thinking and experimenting" led to: instead of manipulating
self.data one now manipulates self:
>>> class UL(list):
... def a(self):
... self[0]+=1
>>> ul=UL([1,2,3])
>>> ul.a()
>>> ul
[2, 2, 3]
Bob Gailer
mailto:ramrom@earthling.net
303 442 2625
--=======7F796E11=======
Content-Type: text/plain; charset=us-ascii; x-avg=cert; x-avg-checked=avg-ok-1CF2B71
Content-Disposition: inline
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.431 / Virus Database: 242 - Release Date: 12/17/2002
--=======7F796E11=======--