1

I'm just starting to learn Python and I decided to start with 3.2

I'm trying some socket managing code and I get a syntax error. (The line works just fine in 2.7)

Any ideas?

        def __init__(self, (socket, address)):
  File "./main.py", line 16
    def __init__(self, (socket, address)):
                       ^
SyntaxError: invalid syntax
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
KillDash9
  • 879
  • 1
  • 8
  • 21

1 Answers1

3

You cannot define a method with a tuple argument in Python 3. This was possible in Python 2 but removed. See PEP 3113 Removal of Tuple Parameter Unpacking.

The syntax made introspection hard, (even impossible for IronPython), was incompatible with other new argument syntax (annotations and keyword-only arguments), produced unhelpful error messages and was one of the least-known and least-used features of the language.

You'll have to do the unpacking in the method:

def __init__(self, socket_address):
    socket, address = socket_address
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343