본문 바로가기
파이썬

파이썬 Python : 빈 목록에서 팝

by º기록 2020. 11. 22.
반응형

내 코드의 루프에서 아래 줄을 사용하고 있습니다.

importer = exporterslist.pop(0)

exportslist에 항목이 없거나 null 이면 error : IndexError : pop from empty list 를 반환합니다. 항목이없는 내보내기 목록을 우회하려면 어떻게해야합니까?

내가 생각할 수있는 한 가지 아이디어는 exportslist가 null이 아니면 importer = exporterslist.pop (0) 입니다. else get the next entry in the loop. 아이디어가 옳다면 파이썬으로 코딩하는 방법은 무엇입니까?

 

해결 방법

 

당신은 올바른 길을 가고 있습니다.

if exporterslist: #if empty_list will evaluate as false.
    importer = exporterslist.pop(0)
else:
    #Get next entry? Do something else?

 

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

 

 

반응형

댓글