recursive function call

Nicolas Vigier boklm at mars-attacks.org
Tue Nov 8 05:16:39 EST 2005


Hello,

I have in my python script a function that look like this :

def my_function(arg1, arg2, opt1=0, opt2=1, opt3=42):
        if type(arg1) is ListType:
                for a in arg1:
                        my_function(a, arg2, opt1=opt1, opt2=opt2, opt3=opt3)
                return
        if type(arg2) is ListType:
                for a in arg2:
                        my_function(arg1, a, opt1=opt1, opt2=opt2, opt3=opt3)
                return
         ... then here the real function code

I'm new to python, so I was wondering if there is a better way to do that.
The reason for a recursive function here is to be able to give lists for
the first 2 args (I could as well use only a simple 'for' without a
recursive call). The problem I have here, is that as I'm working on this
script, I often change the prototype of the function, and each time I
have to think about changing the recursive call too. Is there a way that
I can do a recursive call and say something like "keep all the same
arguments except this one" ?

Thanks

Nicolas

-- 
http://n0x.org/ - boklm at mars-attacks.org





More information about the Python-list mailing list