syntax error python 3.4 tetris game

178 Views Asked by At
def check_block( self, (x, y) ):

    """
    Check if the x, y coordinate can have a block placed there.
    That is; if there is a 'landed' block there or it is outside the
    board boundary, then return False, otherwise return true.
    """
    if x < 0 or x >= self.max_x or y < 0 or y >= self.max_y:
        return False
    elif self.landed.has_key( (x, y) ):
        return False
    else:
        return True

Here there is syntax error in def part, (x,y)... So how could I fix it?

1

There are 1 best solutions below

1
On

Seems like tuple parameter unpacking was removed in Python 3.

So this code

def foo(x, (y, z)):
    print(x, y, z)

foo(1, (2, 3))

Works in Python 2.7

>>> python2 test.py 
(1, 2, 3)

but fails in Python 3

>>> python3 test.py 
  File "test.py", line 2
    def foo(x, (y, z)):
               ^
SyntaxError: invalid syntax

You can also see this with the -3 option in Python 2:

>>> python2 -3 test.py 
test.py:2: SyntaxWarning: tuple parameter unpacking has been removed in 3.x
  def foo(x, (y, z)):
(1, 2, 3)