How to check what arguments an event provides in python?

社会主义新天地 提交于 2021-02-11 13:01:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!