Label-Value (was: Re: Inheriting the @ sign from Ruby)

Daniel Wood daniel at cs.washington.edu
Tue Dec 12 16:24:05 EST 2000


2 would not be mutable.  Certainly.

I'm talking about an *object* that is both an int and mutable.

class MutableInt:
	def __init__( self, default ):
		self.value = default

	def set( self, val ):
		self.value = val

	def get( self ):
		return self.value

	# And maybe
	def __int__( self ):
		return self.value


My question is: am I confused if I think that this might be useful?
And if it is useful then what's the most pythonic way to do this.
(And if the best thing is a list of one element, why isn't that much
more "hack" than "idiom"?)

Thanks,
Daniel.

Darren New <dnew at san.rr.com> writes:

> Daniel Wood wrote:
> > Hmmm, I'm open to the suggestion that I need to rethink my plan at a
> > larger scale, but isn't a mutable int likely to sometimes be useful?
> 
> No. That's why people invented variables.
> 
> Having 
>  x = 2 + 2
>  print x
> result in anything except "4" is probably a *really* bad idea.
> AFAIK, only FORTH and really old Fortrans allow this.



More information about the Python-list mailing list