I figure this is pretty basic, but can\'t seem to figure out even how to ask google the right question. I am using this python websocket client to make some websocket conne
You can use a lambda
to wrap the call:
ws.on_open = lambda *x: on_open("this new arg", *x)
Keep in mind that you need to assign a callback. You are instead calling a function and passing the return value to ws
, which is incorrect.
You can use functools.partial to curry a function to a higher order one:
from functools import partial
func = partial(on_open, "this new arg")
ws.on_open = func
When func
is invoked, it will invoke on_open
with the first argument as "this new arg"
, followed by any other arguments passed to func
. Look at the implementation of partial
in the doclink for more details.