How to change string or number passed as argument?

Hendrik van Rooyen hendrik at microcorp.co.za
Sun Sep 20 10:21:15 CEST 2009


On Sunday 20 September 2009 03:59:21 Peng Yu wrote:

> I know that strings or numbers are immutable when they passed as
> arguments to functions. But there are cases that I may want to change
> them in a function and propagate the effects outside the function. I
> could wrap them in a class, which I feel a little bit tedious. I am
> wondering what is the common practice for this problem.

You can just ignore the immutability.
Nothing stops you doing something like this;

def reader(port,buffer):
    buffer += port.read()
    return buffer

and calling it repetitively until buffer is as long as you want it.

- Hendrik




More information about the Python-list mailing list