Python "why" questions

Neil Cerutti neilc at norwich.edu
Thu Aug 19 13:18:19 EDT 2010


On 2010-08-19, J.B. Brown <jbbrown at sunflower.kuicr.kyoto-u.ac.jp> wrote:
> When I wrote my own C++ 2-D matrix class, I wrote a member
> function which did exactly this - allow you to specify the
> initial index value. Then users of my class (mainly my research
> lab coworkers) could specify whichever behavior they wanted.

I did something similar in a library that needs to read
"positions" from the specification for a fixed-length fields
plain text database.

The printed specs for these document types often start counting
character positions at 1, but not universally.

> For those who don't like Python's 0-based indexing, why not
> just build a wrapper type which features an item() method that
> handles the internal conversion from 1 to 0 as the starting
> index? Better yet, include a method which sets/specifies the
> 0/1 behavior, and have item() reference the 0/1 setting to
> obtain the proper offset.

Because they know deep down they wouldn't win anything.

-- 
Neil Cerutti



More information about the Python-list mailing list