Python Feature Request: Allow changing base of member indices to 1

Paddy paddy3118 at googlemail.com
Sat Apr 14 15:33:26 EDT 2007


On Apr 14, 11:27 am, samj... at gmail.com wrote:
> This is like the previous one. Please check for sanity and approve for
> posting at python-dev.
>
> I would like to have something like "option base" in Visual Basic.
> IIRC it used to allow me to choose whether 0 or 1 should be used as
> the base of member indices of arrays. In Python, the same can be used
> with strings, lists, tuples etc.
>
> This would mean:
> foo = "foo"
> => foo[1] == 'f'
>
> foo = ['foo', 'bar', 'spam' ]
> => foo[1] == 'foo'
>
> foo = ('spam', 'eggs')
> => foo[1] == 'spam'
>
> For convenience it should also affect the range function so that:
>
> range(3) = [1, 2, 3]
>
> because this is often used where arrays would be used in VB.
>
> Finally, when the programmer does not specify his choice of base at
> the beginning of the program, the current behaviour of using 0 as base
> should continue so that there is no problem with backward
> compatibility.

Here is a document giving good reasons for indexing to start at
zero, as in Python.
http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
The author has done a bit:
http://en.wikipedia.org/wiki/Dijkstra

Having more than one index start point would be a maintenance
nightmare best avoided. (It can be done in Perl).

- Paddy.




More information about the Python-list mailing list