SyntaxError: can not assign to operator

0

I'm using the following code:

Levels[track][level] > UnpaidMaxSkills[track] or self.inventory[track][level] += amount

I just get the error:

  

SyntaxError: can not assign to operator

What could be happening?

    
asked by anonymous 11.03.2014 / 13:04

1 answer

3

I do not understand exactly what you want to do with this code snippet, but the error occurs because of a Augmented assignment statement (attribution statement increased?) in an expression.

If I read the documentation correctly, when there is an assignment of this type, the Python interpreter evaluates what is in the right (expression) and assigns it to the left > operator (target). The result of this can not be used in an expression.

In your case, when using the assignment operator += , Python is trying to assign amount to Levels[track][level] > UnpaidMaxSkills[track] or self.inventory[track][level] , but this is not something that can receive an assignment.

I do not quite understand the purpose of this code, but the solution is to make the increment out of expression or other verification. Example:

if Levels[track][level] > UnpaidMaxSkills[track]:
    # fazer algo
else:
    self.inventory[track][level] += amount
    if self.inventory[track][level]:
        # fazer algo
    
11.03.2014 / 15:18