list parameter of a recursive function

TP Tribulations at Paralleles.invalid
Thu Oct 7 01:33:04 EDT 2010


Steven D'Aprano wrote:

>> I think I prefer doing an explicit copy.copy, because it allows to
>> remind the reader that it is very important to take care of that.
> 
> I think a comment is better for that. It's better to explicitly say
> something is important than to assume the reader will guess.

Yes, you are right.

> Besides, what if the caller wants to supply their own list, and they
> *want* it modified in place rather than a copy made? (I have no idea why
> they might want this, but anything is possible...) You should avoid
> making copies except in methods that are *for* making copies.

My function gives a sensible result only if the list is not modified in 
place. In fact, this list is only used internally for the recursion. That is 
why I have made this function "private":

def __relation_loop( sqlite_cursor
        , table_name
        , crossed_tables = None
        , previous_step_link = None
        , onetomany_allowed_depth = 1 ):

I give to the user (me!) only access to the public function:

def relation_loop( sqlite_cursor
        , table_name
        , onetomany_allowed_depth = 1 ):

    return __relation_loop( sqlite_cursor
            , table_name
            , crossed_tables = None
            , previous_step_link = None
            , onetomany_allowed_depth = onetomany_allowed_depth )

So, crossed_tables and previous_step_link, are only used by the recursion 
process, they are not accessible to the user.

-- 
python -c "print ''.join([chr(154 - ord(c)) for c in '*9(9&(18%.\
9&1+,\'Z4(55l4('])"

"When a distinguished but elderly scientist states that something is
possible, he is almost certainly right. When he states that something is
impossible, he is very probably wrong." (first law of AC Clarke)



More information about the Python-list mailing list