-1

I have old Python 2 code that contains

def __init__(self, (gv_to_python, python_to_gv), values, bgl_type='object') :

Using this in Python 3 gives a syntax error (2to3 can't fix this).

What is the Python 3 equivalent of this Python 2 function definition?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

2

PEP 3113 indicates that tuple parameters are being removed. The transition plan at the bottom of that page suggests

Second, the 2to3 refactoring tool [1] will gain a fixer [2] for translating tuple parameters to being a single parameter that is unpacked as the first statement in the function. The name of the new parameter will be changed. The new parameter will then be unpacked into the names originally used in the tuple parameter. This means that the following function:

def fxn((a, (b, c))):
    pass

will be translated into:

def fxn(a_b_c):
    (a, (b, c)) = a_b_c
    pass

Basically, change the parameter into a single value, and unpack it in the body of your function.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Andrew F
  • 2,690
  • 1
  • 14
  • 25