我有一个存储在变量中的未知类的类型
a_type = UnknownType
我想知道这个类型需要实例化多少个参数。
像这样:
expected_number_of_arg = nb_args(a_type)
# where expected_number_of_args = 0 if a_type can be instantiated like this a_type()
这在 python 中可以实现吗?
我有一个存储在变量中的未知类的类型
a_type = UnknownType
我想知道这个类型需要实例化多少个参数。
像这样:
expected_number_of_arg = nb_args(a_type)
# where expected_number_of_args = 0 if a_type can be instantiated like this a_type()
这在 python 中可以实现吗?
该库
inspect
可完成此工作。您传递一个类的函数(不带括号或参数),它会返回参数的数量。这是一个简短的代码,展示了这个库的用法。
至于版权信息,我是通过谷歌搜索找到的,并且公然借用了Geeks for Geeks 的内容。