str and __setitem__

Tor Erik Soenvisen toreriks at hotmail.com
Thu Jan 25 05:16:31 EST 2007


Hi,

What do I need to do to make the code below work as expected:

class str2(str):

	def __setitem__(self, i, y):
		assert type(y) is str
		assert type(i) is int
		assert i < len(self)

		self = self[:i] + y + self[1+i:]


a = str2('123')
a[1] = '1'
print a
123


The print statement should return 113

Regards tores



More information about the Python-list mailing list