Hi all,
I need some help with my code, because I have a bit of trouble with using the cur.execute in the loops.

When I try this:

for pos_X, pos_Y, prog_id, prog_width in zip(positions_X, positions_Y, programs_id, program_width):
    cur.execute('SELECT button_ids, button_width FROM buttons where button_ids=?', [prog_id))
    if int(pos_X) == 375:
       if int(prog_width) == 342:
           self.getControl(int(prog_id)).setVisible(False)

It will work fine but I can't get self.getControl to work unless if I have to fire the code twice.

So if I try this:

for pos_X, pos_Y, prog_id, prog_width in zip(positions_X, positions_Y, programs_id, program_width):
        #cur.execute('SELECT button_ids, button_width FROM buttons where button_ids=?', [prog_id))
        if int(pos_X) == 375:
           if int(prog_width) == 342:
               self.getControl(int(prog_id)).setVisible(False)

It will work fine without have any problem.

Here is the full code:

for pos_X, pos_Y, prog_id, prog_width in zip(positions_X, positions_Y, programs_id, program_width):
    cur.execute('SELECT button_ids, button_width FROM buttons where button_ids=?', [prog_id])
    buttons = cur.fetchall()

    for ind, row in enumerate(buttons):
        button_id = str(row[0])
        button_width = str(row[1])
        buttonList.append(button_id)
        buttonWidthList.append(button_width)
    buttons_id = map(str, buttonList)
    buttons_width = map(str, buttonWidthList)


    for program_id, program_width in zip(buttons_id, buttons_width):
        for pos_X, pos_Y, prog_id, prog_width in zip(positions_X, positions_Y, programs_id, program_width):
            if int(pos_X) == 375:
                if int(prog_width) == 342:
                    print program_id

I want to check in the elements pos_X to see if I have the value 375 and I want to check in the elements prog_width to see if it have the value 342 then I want to call the database to find for the matched elements of prog_id then I want to pull the information from the database to get the width size before I use to call the object self.getControl.

Can somebody please help me with this?

Recommended Answers

All 2 Replies

does anyone know???????

This code is very difficult to understand. The first healthiness rule is that if a variable name is set in a loop condition, such as pos_X or prog_id in

for pos_X, pos_Y, prog_id, prog_width in zip(positions_X, positions_Y, programs_id, program_width):

then the same variable must not be redefined inside the body of the for loop. It means that you must not write another for pos_X, pos_Y... inside the first loop's body. Use different variable names, such as pos_X2, pos_Y2,... if you must reuse similar variables inside the loop.

Second thing that makes the code difficult to understand is the use of variable names which differ only by the plural of the word, such as button_id and buttons_id.

Third thing that's not obvious: are button ids and prog ids the same thing ? It seems to be in your call to cur.execute(). This is very confusing.

These may be the reasons why nobody knows the answer :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.