Guide to the python interp. source?

Martin v. Loewis martin at v.loewis.de
Sat Jul 27 18:13:17 EDT 2002


"Tim Gahnström /Bladerman" <tim at bladerman.com> writes:

> when it comes to calling functions it will look like this
> 
> def setTo3(x):
>     x=3
> 
> a=2
> setTo3(a)

Others have already suggested that this will be impossible to
implement, but I guess I can't stop you from trying, so I won't.

Instead, I suggest that this is already possible with a slightly
different notation

def setTo3(x):
  x.assign(3)

a=Reference(2)
setTo3(a)

All this requires is

class Reference:
  def __init__(self, value): self.value = value
  def assign(self, value): self.value = value

Regards,
Martin




More information about the Python-list mailing list