Printable string for 'self'

Duncan Booth duncan.booth at invalid.invalid
Thu Mar 16 03:49:35 EST 2006


Michael Tobis wrote:

> I got in some trouble in these parts a few months back for advocating
> some sort of immutable reference, like
> 
> fred -> C("fred")
> 
> where any reassignment of the refernce during the lifetime of the
> referent would raise an exception. This seems to be seen as wrongheaded
> by greater pythonistas than myself.  I don't fully understand *why*
> this is a bad idea, but my intuitive idea that it would be very
> valuable has gone away.
> 

>>> fred = C("fred")
>>> jim = fred
RebindingError: cannot rebind <C object 'fred'> to name "jim"
>>> def showit(x):
    print x

    
>>> showit(fred)
RebindingError: cannot rebind <C object 'fred'> to name "x"
>>> fred.amethod()
RebindingError: cannot rebind <C object 'fred'> to name "self"
>>> fred.aclassmethod()
That works!
>>> sys.getrefcount(fred)
RebindingError: cannot rebind <C object 'fred'> to name "object"
>>> del fred
>>>

What were you planning to do with this object exactly that didn't involve 
binding it to any other names during its lifetime?



More information about the Python-list mailing list