how to pass by reference??

Grant Edwards grante at visi.com
Sun Feb 3 23:27:19 EST 2002


In article <a3knt6$gr3$1 at news.efn.org>, Spencer Doidge wrote:

> I really tried to RTM first this time, but I failed.
> Can someone give me a hint where in the doc html's it explains how to pass
> by reference?

Everything in Python is passed by reference.  Always.

However, some of those "things" can't be changed, so it may or may not be
possible to do what you want.  Strings can't be changed, so strictly
speaking it's not possible to do what you ask below.  Lists can be changed,
so you could modify them in-place as shown in your C code.  Perhaps you
could explain what it is you're trying to accomplish and we could explain
how it is typically done with Python?

> Specifically, I want to do the equivalent of this:
> 
> char s[10];
> 
> void foo(char *bfr)
> {
> bfr[0] = 'a';
> bfr[1] = 'b';
> return;
> }
> 
> void main(void)
> {
> foo(s);
> return;
> }



-- 
Grant Edwards                   grante             Yow!  People humiliating
                                  at               a salami!
                               visi.com            



More information about the Python-list mailing list