Recursive functions

Tom Harris tomh at optiscan.com
Thu Jun 28 02:28:28 EDT 2001


Hi,

I am very new to Python, and I am trying to get a recursive function
working. The problem is that the function modifies one of its arguments,
which is not a local copy of a variable (local to this stack frame of the
function, like in call by value in C) but a reference to a variable owned by
the function namespace, so changes to the variable are inherited by other
calls to the same function. I tried copying the argument to a variable in
the function body, but of course this suffers from the same problem.

This is the idea, but the list just keeps on growing.

def f(aList):
	...
	aList.append(stuff)
	f(aList)

What is the solution? 

 Tom Harris, Software Engineer
 Optiscan Imaging, 15-17 Normanby Rd, Notting Hill, Melbourne, Vic 3168,
Australia
 email tomh at optiscan.com     ph +61 3 9538 3333  fax +61 3 9562 7742

This email may contain confidential information. If you have received this
email in error, please delete it immediately,and inform us of the mistake by
return email. Any form of reproduction, or further dissemination of this
email is strictly prohibited.
Also, please note that opinions expressed in this email are those of the
author, and are not necessarily those of OptiScan Pty Ltd







More information about the Python-list mailing list