changing value of 'self' when subclassing int

David Coffin dcoffin at gmail.com
Tue Feb 21 12:34:27 EST 2006


Thanks for all the help.

> On 20 Feb 2006, at 17:34, Alex Martelli wrote:
>
> ...integers are immutable, like all other numbers in Python: there  
> is NO
> way to "change the value of the integer itself".

So, on learning that I could subclass the number types, I didn't even  
consider the fact that they're immutable. I feel slightly foolish.  
And I'll look at gmpy straight away, it looks like it contains  
functionality I'll find useful.

> On 21 Feb 2006, at 10:58, Fuzzyman wrote:
>
> Probably your best bet is to have the assignment done as a method call
> which returns the new value.

I not sure that would be suitable in this case. I'm using genetic  
algorithm code containing some methods that assume 'individuals' are  
represented as bitstrings, and some that assume individuals are  
represented as lists of integers. Ideally, I could have created a  
class for the bitstring individuals that also supported list based  
bit assignment (without too much overhead).

Best wishes,
David Coffin



More information about the Python-list mailing list