본문 바로가기
파이썬

파이썬 함수를 호출 할 때 목록을 * args로 변환

by º기록 2020. 10. 30.
반응형

Python에서 목록을 * args 로 어떻게 변환합니까?

기능이

scikits.timeseries.lib.reportlib.Report.__init__(*args)

몇 개의 time_series 객체가 * args 로 전달되기를 원하지만 나는 timeseries 객체 목록이 있습니다.

 

해결 방법

 

iterable 전에 * 연산자를 사용하여 함수 호출 내에서 확장 할 수 있습니다. 예를 들면 :

timeseries_list = [timeseries1 timeseries2 ...]
r = scikits.timeseries.lib.reportlib.Report(*timeseries_list)

( timeseries_list 앞에 * 주의)


* expression 구문이 함수 호출에 나타나면 expression must evaluate to an iterable. Elements from this iterable are treated as if they were additional positional arguments; if there are positional arguments x1, ..., xN, and expression evaluates to a sequence y1, ..., yM, this is equivalent to a call with M+N positional 인수 x1, ..., xN, y1, ..., yM.


 

참조 페이지 https://stackoverflow.com/questions/3941517

 

 

반응형

댓글