분석 Python/구현 및 자료
[ Python ] 파이썬 함수 argument 정보 가져오기
데이터분석뉴비
2020. 2. 8. 19:13
728x90
파이썬 내부에서 argument를 어떤 것을 넣는지 다 가져오고 싶을 때가 있다.
그래서 이러한 문제를 inspect 함수로 해결하는 것을 알 수 있었다.
import inspect
def a(a=5,b=5) :
frame = inspect.currentframe()
args, _, _, values = inspect.getargvalues(frame)
del values["frame"]
print(args , values)
a(5,2)
import inspect
class Argument(object) :
def __init__(self,name) :
self.name= "go"
def test(self, a=5,b=5, **kwargs) :
frame = inspect.currentframe()
args, _, _, values = inspect.getargvalues(frame)
del values["frame"]
ck_kwargs = values.get("kwargs",None)
if ck_kwargs is not None :
values.update(ck_kwargs)
del values["kwargs"]
del values["self"]
print(args , values)
f = Argument("test")
f.test(a=5,b=5,c=10)
https://stackoverflow.com/questions/582056/getting-list-of-parameter-names-inside-python-function
Getting list of parameter names inside python function
Possible Duplicate: Getting method parameter names in python Is there an easy way to be inside a python function and get a list of the parameter names? For example: def func(a,b,c): print
stackoverflow.com
728x90