Re: [Tutor] working with new classes

2005-03-09 Thread Kent Johnson
C Smith wrote: Alternatively, the list class can be appended with helpers like 'turn' and 'segment' which can actually turn the "ring" and remove a piece from it without worrying about the endpoint: ### >>> class ring(list): def turn(self, incr=1): incr%=len(self) self[:]

Re: [Tutor] working with new classes

2005-03-09 Thread C Smith
Thanks to Sean and Kent for replies. I found a site that provided some good examples, too, at http://www.cafepy.com/articles/python_attributes_and_methods/ ch03s02.html Here's a blurb from the title page: wep page excerpt Shalabh Chaturvedi Copyright © 2004 Shalabh Chaturvedi This book

Re: [Tutor] working with new classes

2005-03-09 Thread Kent Johnson
Sean Perry wrote: C Smith wrote: ### class Ring(list): def __init__(self, l): self[:] = l self._zero = 0 def turn(self, incr=1): self._zero+=incr def __getitem__(self, i): return self[(i-self._zero)%len(self)] l=Ring(range(10)) print l l.turn(5) pr

Re: [Tutor] working with new classes

2005-03-09 Thread Sean Perry
C Smith wrote: ### class Ring(list): def __init__(self, l): self[:] = l self._zero = 0 def turn(self, incr=1): self._zero+=incr def __getitem__(self, i): return self[(i-self._zero)%len(self)] l=Ring(range(10)) print l l.turn(5) print l#same a

[Tutor] working with new classes

2005-03-08 Thread C Smith
Hello, After learning about the new class behavior, I am trying to implement a circular type list where, for example, you can compare the nth value to the "(n+1)th" value without worrying about going past the end of the list. (An old approach might be to create a function that converts a given