Design Q: Changing the indexing of a list

Matt matt_crypto at yahoo.co.uk
Sat Feb 14 00:48:21 CET 2004


Hello, I was wondering if anyone could suggest a way of doing the
following in Python: I'm writing a class to handle strings of bits,
and I often need to number the bits in different ways,  e.g. from the
left starting at zero, or from the right starting at one, and so
forth. I'd quite like to be able to dynamically change how
subscripting works for individual objects, and maybe have that
behaviour transferred to any further objects that that individual
creates (e.g. a new bit string that's the logical negation of the
original). There's actually a couple of other things like that as
well, such as being able to set whether the "+" operation means
concatenation or addition for an object.

This might sound like a horrible thing to want to do, given that it
would then be hard to know what indexing or addition would do in any
given context, but it would be very convenient in the application I'm
looking at. Any suggestions on how I might go about this would be much
appreciated,

Matt



More information about the Python-list mailing list