Issue
I have a function definition as follows:
def test(self, *args, wires=None, do_queue=True):
pass
In Python3, this runs normally, but in Python2 it crashes with a SyntaxError. How can I modify it to work in Python2?
Solution
The only way to make this work in Python 2 is to accept your keyword-only arguments as **kwargs
and extract them manually. Python 2 has no ability to do keyword-only arguments in any other manner; it was a new feature of Python 3 to allow this at all.
The closest Python 2 equivalent would be:
def test(self, *args, **kwargs):
wires = kwargs.pop('wires', None)
do_queue = kwargs.pop('do_queue', True)
if kwargs:
raise TypeError("test got unexpected keyword arguments: {}".format(kwargs.keys()))
Answered By - ShadowRanger
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.