IT/Programming 4

[Python] python float 'nan', 'inf' 처리

문제상황 txt에 nan과 inf, float 값이 저장된 파일을 읽어와서 다시 float 값으로 변환하고, nan과 inf는 경계값으로 설정하려 했는데 되지 않았다. 생각해보니 map(float, target_list)에서 에러가 생기지 않아서 'nan', 'inf' 모두 float 함수가 실행되긴 했다는 뜻이었다. print(float('nan')) # nan print(type(float('nan')) # print(float('nan') == float('nan')) # False print(float('nan') is float('nan')) # False print(float('nan') is type(float('nan'))) # False print(float('inf')) # inf 해결..

IT/Programming 2023.12.02

[Python] A load persistent id instruction was encountered,but no persistent_load function was specified. 해결

문제 상황 with open(f"./{dir_name}/agents/{id_code}", "rb") as file: saving_list.append(pickle.load(file)) Exception has occurred: UnpicklingError A load persistent id instruction was encountered, but no persistent_load function was specified. .pickle로 저장해둔 object를 불러오려 했는데, 에러가 발생했다. 해결 확장자에 주의한다!(.pickle) 코드를 수정하다가 .pickle이란 확장자를 지우고 파일 이름까지만 작성해둬서 파일이 제대로 인식되지 않은 것 같다. '.pickle' 이란 확장자를 명확히 기술하는 ..

IT/Programming 2023.07.02

[Python] dictionary changed size during iteration 해결

문제 상황 keys = target_dict.keys() for key in keys: if condition(key): target_dict.pop(key) Runtime Error: dictionary changed size during iteration 딕셔너리에서 key를 체크하면서 조건에 맞는 key-value pair를 제거하려 했는데, 에러가 났다. 해결 target_dict.keys() 대신 list(target_dict.keys()) 를 이용한다. .keys() method는 list가 아니라 dict와 연결된 iterable object를 반환하는 것 같다. keys = list(target_dict.keys()) for key in keys: if condition(key): targ..

IT/Programming 2023.06.24