Python bug? Named parameters in recursive calls sometimes confuses python?

Duncan Booth duncan at NOSPAMrcp.co.uk
Fri Nov 28 13:49:51 CET 2003


magnus at thinkware.se (Magnus Lyck?) wrote in
news:258fd9b8.0311271503.c134a25 at posting.google.com: 

>     def recursiveCopy(self, table, column, old_val, new_val):
>         # Fetch row from source database
>         print "1. Column %s (%i) Table %s (%i)" % (column, id(column),
>                                                    table, id(table))
> 
>         sql = "SELECT * FROM %(schema)s.%(table)s WHERE %(column)s =
>         ?" rows = self.src_fetch(sql, params=(old_val,), table=table,
>                               column=column)
>                # I use "sql % kwargs" in a method called by src_fetch
> 
>         print "2. Column %s (%i) Table %s (%i)" % (column, id(column),
>                                                    table, id(table))
> 
>         for row in rows:
>             # Replace foreign key with value for target DB
> 
>             print "3. Column %s (%i) Table %s (%i)" % (column,
>             id(column), 
>                                                        table,
>                               id(table)) 
> 
>             row[column] = new_val  # <= This is where it crashes.
>             # What's interesting is the print above before the crash.
>             # row is a db_row.IMetaRow instance instance.
> 
>             # We need primary key values for recursive find
>             # Only bother for table with a single p.k.
>             parent_p_key_cols = self.getPK(table)
>             if len(parent_p_key_cols) == 1:
>                 parent_p_key_col = parent_p_key_cols[0]
>                 oldId = row[parent_p_key_col]
>                 newId = self.insertIntoTarget(table, row)
>                 for child_table, column in self.getDepTables(table,
>                                                             
>                               parent_p_key_col): 
>                     self.recursiveCopy(child_table, column, oldId,
>                     newId) 

I note that you reassign the 'column' variable in that last for loop. I 
think your last line of output is simply the second time around the 'for 
row in rows' in the outermost call. Perhaps if you used a different 
variable name for that second variable called 'column' you wouldn't get so 
confused.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list