On Sun, 5 Mar 2017 at 18:13 David Mertz <me...@gnosis.cx> wrote: > But if the next line is: > > data = args.get(17, "<empty>") > > Then I'm pretty sure the programmer thinks she's being passed a very > different type of collection than is actually available. I'd rather that > fails right away and in an obvious way then silently produce a value. >
That's up to the programmer. args[17] exists and does fail immediately. If the programmer provides a default value, presumably they know they want one. > Specifically, if I think I'm dealing with a list that is likely to have 20 > items (rather than maybe 4 or fewer), I'm almost sure the best way to deal > with it is in a loop (or comprehension, map(), etc) and NOT by poking into > large index positions that may or may not be present. > I really think that depends what it's a list of. If the positions of things in the list are important (as with an argument parser, or perhaps a lookup table) I fail to see why it would be wrong to peek. If lists were really designed to be used only as you and some others in this thread are suggesting, I don't think they'd have indexed access at all. Ed
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/