UserList.__getslice__(): copy.copy(self.data) vs. self.__class__(self.data).
Tom Funk
_spam_sux_tdfunk at _spam_sux_nettally.com
Tue Mar 14 23:56:33 EST 2000
More information about the Python-list mailing list
Tue Mar 14 23:56:33 EST 2000
- Previous message (by thread): UserList.__getslice__(): copy.copy(self.data) vs. self.__class__(self.data).
- Next message (by thread): UserList.__getslice__(): copy.copy(self.data) vs. self.__class__(self.data).
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi, Bernhard: In an article posted 15 Mar 2000 00:25:29 +0100, Bernhard Herzog (herzog at online.de) said: > > Note that missing > > i or j in the slice expression are replaced by zero or > > sys.maxint, respectively, ... > It seems negative indices are automatically subtracted from the length. Actually, this behavior matches the description in the Language Reference Manual. > UserList has only one instance variable, data, and that is handled > correctly. If you need to copy more variables in a derived class you > should probably override this method, IMO. OK. > Note that all slicings succeed for normal lists. If both indices of the > slice are too large or too small (i.e. too negative ;-) ) the result is > an empty list. Uh.... I stand before you hat in hand begging forgiveness.... I just went back and tried this in interactive mode: >>> l=[0,1,2,3,4,5,6] >>> l[-10] Traceback (innermost last): File "<interactive input>", line 1, in ? IndexError: list index out of range >>> l[-100:-99] [0, 1] >>> l[-100:-50] [0, 1, 2, 3, 4, 5, 6] >>> l[-100:-50] [] >>> l[-10:-100] [] >>> # damn! And, of course, you are correct. The error resulted from an index error (I.e, the runtime called the native equivalent of __getitem__(self, I)). I don't know what I was doing before (other than embarrassing myself :-/) > A normal list doesn't raise an IndexError here. It returns [0, 1, 2, 3] > Even ul[-10:-100] succeeds for a normal list, returning [] . Yes it does... see above. OK, you and Alex win: UserList stays as it is, and I sit back down in my chair and shut-the-heck-up <g>. I was thinking that we'd be left with why test_userlist.py was failing.... but NOT! Even that seems to have remedied itself: D:\Python\Lib\test>python test_userlist.py D:\Python\Lib\test> So, I'm truly sorry to have wasted everyone's time. I was *way* off- based with my testing/assessment/findings. Thank you Bernhard and Alex for setting me straight. <sheepish g> -- -=< tom >=- Thomas D. Funk | "Software is the lever Software Engineering Consultant | Archimedes was searching for" Advanced Systems Design, Tallahassee FL. |
- Previous message (by thread): UserList.__getslice__(): copy.copy(self.data) vs. self.__class__(self.data).
- Next message (by thread): UserList.__getslice__(): copy.copy(self.data) vs. self.__class__(self.data).
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list