¿No te falta un paréntesis de cierre en esta línea? > d.execute(""" select attname from > pg_attribute where attnum='%s' and attrelid='%s' > """)%(i[2][t],i[0])