Fixing Python Function Error with Positional Only Argument

Your #Python function takes a filename and **kwargs. But this raises an error, since "filename" is passed twice: myfunc('outfile.txt', filename='abcd', x=100) Solution: Set filename to be positional only: def myfunc(filename, /, **kwargs): Now *any* keyword argument works!

  • No alternative text description for this image

cool, but perhaps you shouldn't be calling the variable `filename` at all? :-P

To view or add a comment, sign in

Explore content categories