1

So I'm analyzing this code and I have reason to believe this was coded with python 2.X but I'm using 3.2 and would like to convert it so that it would work.

The first error I encountered was with a function with a syntax

def function((x,y))

Why doesn't it work in Py3 and what's the alternative?

sloth
  • 99,095
  • 21
  • 171
  • 219
Prince Merluza
  • 133
  • 1
  • 9

2 Answers2

5

As Mr E already said in the comment, this feature was removed in Python 3 with PEP 3113. The alternative is very simple, you just have a single parameter which you unpack manually:

def func (xy):
    x, y = xy
    # ...

Or you define the function with two parameters, and make users of the function unpack their values themselves:

def func (x, y):
    # ...

t = (1, 2)
func(*t)

Btw. it’s a good idea to run Python’s 2to3 tool to convert existing Python 2 code to match Python 3’s syntax and library changes.

poke
  • 369,085
  • 72
  • 557
  • 602
1

2to3 will, in theory, take care of this for you. I say "in theory" because I have not used it, but most of Python works as advertised.

hd1
  • 33,938
  • 5
  • 80
  • 91