获取函数的关键字参数,Python [英] Get Keyword Arguments for Function, Python

查看:67
本文介绍了获取函数的关键字参数,Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

def thefunction(a=1,b=2,c=3):
    pass

print allkeywordsof(thefunction) #allkeywordsof doesnt exist

这将给[a,b,c]

which would give [a,b,c]

有没有类似allkeywordsof的功能?

Is there a function like allkeywordsof?

我无法更改内部任何内容,功能

I cant change anything inside, thefunction

推荐答案

您想要这样的东西吗?

>>> def func(x,y,z,a=1,b=2,c=3):
    pass

>>> func.func_code.co_varnames[-len(func.func_defaults):]
('a', 'b', 'c')

这篇关于获取函数的关键字参数,Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆