List slice assignment and custom sequences

Ronald Oussoren oussoren at cistron.nl
Sat Nov 2 11:15:49 EST 2002


Hi,

I have a custom sequence-class (actually a proxy for a native type) and 
would like to use this just like a normal list. This is mostly working 
just fine by defining __getitem__ et.al., but I cannot use the type as 
the RHS of an assigment to a list slice.

I traced this to the implementation of this feature in type 'list': It 
requires that the new version of the slice is also a 'list':

	l = [ 1, 2, 3, 4]
	l[1:3] = range(10)	# works fine
	l[1:3] = xrange(10) # raises TypeError

Why must the RHS side of 'l[1:3] = expr()' be an instance of 'list'?

Ronald





More information about the Python-list mailing list