[IronPython] Slicing old-style classes
Sanghyeon Seo
sanxiyn at gmail.com
Wed Aug 30 10:55:43 CEST 2006
Bah, I *hate* this particular historical artifact of Python (which
shall be removed in the future...), but there are codes depending on
this.
For example, pyasn1 http://pyasn1.sourceforge.net/ does.
Python originally didn't have slice type, only slice syntax. So Python
converted indicies and passed them to __getslice__. Later, slice type
was introduced and __getslice__ deprecated. For compatibility,
old-style classes still get indicies converted, new-style classes
don't.
class OldStyle:
def __getitem__(self, index):
return index
class OldStyleWithLen:
def __getitem__(self, index):
return index
def __len__(self):
return 10
class NewStyle(object):
def __getitem__(self, index):
return index
print NewStyle()[:-1]
print OldStyleWithLen()[:-1]
print OldStyle()[:-1]
Seo Sanghyeon
More information about the Ironpython-users
mailing list