K
Kreso
I am subclassing list class and it basically works, but I don't
understand why after splicing these mylist objects I don't get
returned mylist objects. What I get are list objects:
class mylist(list):
def __init__(self):
list.__init__(self)
k = mylist()
k.append(1)
k.append(2)
k.append(3)
print type(k) # prints <class '__main__.mylist'> as expected
m = k[:1]
print type(m) # prints <type 'list'> ???
I would prefer that resulting object m belonged to myclist class.
How to obtain such behaviour? Must I somehow implement __getslice__
method myself?
(It's python 2.5.2, BTW)
understand why after splicing these mylist objects I don't get
returned mylist objects. What I get are list objects:
class mylist(list):
def __init__(self):
list.__init__(self)
k = mylist()
k.append(1)
k.append(2)
k.append(3)
print type(k) # prints <class '__main__.mylist'> as expected
m = k[:1]
print type(m) # prints <type 'list'> ???
I would prefer that resulting object m belonged to myclist class.
How to obtain such behaviour? Must I somehow implement __getslice__
method myself?
(It's python 2.5.2, BTW)