anything like C++ references?
Aahz
aahz at pythoncraft.com
Sun Jul 13 13:40:13 EDT 2003
In article <13t0hvsb7idh0g6ac3upe5k0qd6flc17ah at 4ax.com>,
Tom Plunket <tomas at fancy.org> wrote:
>
>I want to do something along the lines of the following C++ code:
>
>void change(int& i)
>{
> i++;
>}
class Counter:
def __init__(self, start=0):
self.counter = start
def inc(self, increment=1):
self.counter += increment
def change(counter):
counter.inc()
There's no need to get into all the special methods required to
implement a number type, and it's a Bad Idea to use a random container
object. Just pass around a mutable class instance, and your code
becomes simpler and clearer.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"Not everything in life has a clue in front of it...." --JMS
More information about the Python-list
mailing list