So I have a function defined as such:
def getDistnace(self, strings, parentD, nodeName, nodeDistance):
And I am calling it with:
Node.getDistnace(newNode, strings, parentD, nodeName=None, nodeDistance=None)
and
Node.getDistnace(node, strings=None, parentD=None, nodeName, nodeDistance)
Which are both from 2 other different functions. But my problem is that I get an error stating there is a non-keyword arg after keyword arg.
Is there any way around this error? The first Node.getDistnace adds strings and parentD to getDistance, and the second Node.getDistnace adds nodeName and nodeDistance to the function.
All your arguments are positional, you don’t need to use keywords at all:
I think you are confusing local variables (what you pass into the function) and the argument names of the function. They happen to match in your code, but there is no requirement that they do match.
The following code would have the same effect as your first example:
If you do want to use keyword arguments, that’s fine, but they cannot be followed by positional arguments. You can then alter the ordering and python will still match them up:
Here I moved
nodeDistanceto the front of the keyword arguments, but Python will still match it to the last argument of thegetDistnacemethod.