问题
I have a functioning event listener and delegate handler like this:
def eHandler(source, sym, bid, ask) :
qstr = '{} {:.5f} {:.5f}'.format(sym,bid,ask)
print(qstr)
...
mtc.QuoteUpdated += eHandler
However, I suspect the event also provide an object (?) with keywords which I don't know what they are. I have tried to do something like the following, but it doesn't work.
def eHandler2(src, *args, **kwargs):
k = args
print('{} {:.5f} {:.5f}'.format(k.Instrument, k.Bid, k.Ask))
print('src: {}\nargs: {}\nkwargs: {}'.format(src, list(args), list(kwargs)))
How can I check if there are any keywords or other objects provided by the event?
(And how can I find out what they are?)
PS. Using Python3 and pythonnet for events coming from a .NET DLL, which I do not know what is provided.
Some possibly related questions:
- python check if function accepts **kwargs
- Can you list the keyword arguments a function receives?
- Get Keyword Arguments for Function, Python
- Check if a function uses a specific keyword argument
来源:https://stackoverflow.com/questions/65064101/how-to-check-what-arguments-an-event-provides-in-python