I have some python3 code that I'm trying to make compatible with python2. This has mostly been easy using the six
package and __future__
, but I can't find a way around 'extended unpacking' (i.e. using the *args
syntax). For example, the function:
def func(a, *args, b=None, **kwargs):
pass
What is the most elegant and/or simplest way to make this compatible with both python2 and python3? Is there any solution in six
, e.g. a wrapper or something?
While the question "Default arguments with *args and **kwargs" is similar, it's solution is to use a different function instead of making the example one work (although, of course, that may be impossible). i.e. func(a, b=None, *args, **kwargs)
instead.
Since it raises a SyntaxError
before execution a try-except
won't work...