[NEWBIE] Sequence indices & method docstrings
Erik Max Francis
max at alcyone.com
Mon Sep 4 14:44:50 EDT 2000
Paul-Michael Agapow wrote:
> The first concerns sequence indices. It seems to me there are two
> different ways in which they work. Under simple use (myList[4],
> myList[-1]) via __getitem__ and __setitem__ the allowable keys are
> [-len...len-1] where negative numbers wrap around to the end of the
> sequence. This also applies to slice notation. However insert()
> interprets any negative indice as a prepend and any indice >= len as
> an
> append. This _seems_ inconsistent to me. What's the rational or model
> behind this?
The Python FAQ has an entry (4.58) on this. See (the www.python.org Web
site appears to be down at the moment, so here's a mirror):
http://www.cs.tu-berlin.de/usr/python/doc/FAQ.html#4.58
> Point the second: in a set of container classes I'm implementing, I
> have
> some synonym methods, i.e. methods with different names that just call
> the other implemented function. Ideally, these should share the same
> docstring, but instead of just copying it, I thought it would be easy
> to
> just put in:
...
> def enqueue (self, item):
> __class__.push.__doc__
...
I'm pretty sure that the docstrings have to be string literals, so
there's no way to do this in-class.
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/ \ That it will never come again is what makes life so sweet.
\__/ Emily Dickinson
Polly Wanna Cracka? / http://www.pollywannacracka.com/
The Internet resource for interracial relationships.
More information about the Python-list
mailing list