user1961756
user1961756

Reputation: 9

"Expected::" error in python

beginning to learn python, so sorry if this is elementary. Why is the error "Expected::" calls by this code:

cur.execute('''SELECT error FROM WT_enercon_bawnmore WHERE error <> 0;''')
count = 0
for key in d:
    for i in cur:
        if key = i:
            count += 1
    d[key] = count

Eclipse is indicating that the fifth line is the route of the problem. Thanks in advance.

Upvotes: 0

Views: 35206

Answers (3)

jtg
jtg

Reputation: 11

The error you're getting is stating that it expected to get an expression it could evaluate. Instead it sees that you are trying to make a variable assignment in your if statement.

key = i # assign i to key
key == i # evaluate equality of i and key

An if statement expects something that can be evaluated to either True or False, like key == i.

Upvotes: 1

juankysmith
juankysmith

Reputation: 12448

When programming in Python, you use '=' to assign values to the variable, if you want to compare you have to use '=='

Upvotes: 2

jgr
jgr

Reputation: 3974

You need to write:

if key == i:

Since you check it, not assigning it.

Upvotes: 9

Related Questions