728x90 반응형 에러코드4 [Python] local variable 'profit' referenced before assignment |파이썬 에러코드| 예외가 발생했습니다. UnboundLocalError 발생 시 코드 수정 방법 에러 메시지 : local variable 'profit' referenced before assignment 발생 경우 : 변수 호출을 하지 못 할 때 발생 원인 : 전역 변수를 지역 변수로 호출할 때 해당 메시지가 발생 해결 방법 : 해당 변수를 함수 안에 전역 변수로 선언 해 주면 됨 ex) 오류 발생 하는 코드 def btc_check(): if btc_open != 0 and btc_close != 0: profit = round(((btc_close - btc_open) / btc_open) * 100, 2) print(f'등락률 : {profit}) 수정한 코드 def btc_check(): g.. 2021. 10. 23. [Python] dictionary changed size during iteration |파이썬 에러코드| 예외가 발생하였습니다. Runtime Error 발생 시 코드 수정 방법 에러 메시지 : dictionary changed size during iteration 발생 경우 : loop문 도중 dictionary key 값을 삭제할 때 발생 원인 : python에서는 dictionary를 mutable한 변수로 보고 있고 데이터가 변경되면 이를 반영하기 때문이다. 그렇기 때문에 iteration을 수행하는 도중에 key가 삭제되면 사이즈 변경을 인지하여 runtime 에러를 발생시키는 것이다. [출처] [python3] RuntimeError: dictionary changed size during iteration 해결하는 방법|작성자 예스베이비 취미가 다양한 개발자 : 네이버 블로.. 2021. 10. 20. [python] ValueError: Your version of xlrd is 2.0.1. In xlrd >= 2.0, only the xls format is supported. Install openpyxl instead. |파이썬 에러코드| ValueError: Your version of xlrd is 2.0.1. In xlrd >= 2.0, only the xls format is supported. Install openpyxl instead. 발생 경우 : 엑셀파일 읽기 진행 중 확장자 .xlsx를 읽기 할 때 발생하는 에러 코드 원인 : xlrd 라이브러리 버전이 2.0 이상일 때는 확장자 .xls 밖에 지원하지 않음 해결 방법 : 확장자 .xls 를 읽기 pip install openpyxl 2021. 3. 23. [python] AttributeError: 'set' object has no attribute 'items' |파이썬 에러 코드| AttributeError: 'set' object has no attribute 'items' 발생 경우 : 크롤링 하기 위해 헤드 부분에 User-Agent 변수 값을 사용할 때 발생 원인 : User-Agent 헤드 양식이 틀렸을 경우 발생 해결 방법 : 아래 사이트에서 www.useragentstring.com/ UserAgentString.com - unknown version www.useragentstring.com User-Agent : 뒤에 빨간 박스에 있는 값을 입력 headers = {"User-Agent" : " 빨간 박스의 값 "} 2021. 3. 23. 이전 1 다음 반응형