상세 컨텐츠

본문 제목

파이썬 에러 해결

Python

by 견오수 2021. 9. 18. 00:44

본문

728x90

1. PermissionError: [Errno 13] Permission denied 

 

리눅스 chmod +x 등으로 실제 파일 권한을 변경해줄 수 있지만,
windows에서는 Windows 등에서 오류가 나는 이유의 대다수는 경로 문제 및 파일 확장자 문제이다. \\,/ 확인해야한다.

 

2. UnicodeDecodeError: 'cp949' codec can't decode byte 0xf0 in position 9: illegal multibyte sequence

 

cp949 코덱으로 인코딩 된 파일을 읽어들일때 발생 -> open('파일경로.txt', 'rt', encoding='UTF8')

 

3. OSError: [Errno 22] Invalid argument:

 

파일 저장할 때 경로 혹은 파일의 이름명에 들어가면 안되는 문자가 있을 수가 있다. 상위 하위폴더 D:\하위폴더\\

 

4.[파이썬] OSError: [WinError 123] 파일 이름, 디렉터리 이름 또는 볼륨 레이블 구문이 잘못되었습니다.

windows에서 파일명에 들어가면 안되는 문자열을 대체해주는 코드이다.

try:
    if '\\' or '/' or ':' or '*' or '?' or '"' or '<' or '>' or '|' in file_name:
        file_name = file_name.replace('\\', '_')
        file_name = file_name.replace('/', '_')
        file_name = file_name.replace(':', '_')
        file_name = file_name.replace('*', '_')
        file_name = file_name.replace('?', '_')
        file_name = file_name.replace('<', '_')
        file_name = file_name.replace('>', '_')
        file_name = file_name.replace('|', '_')
except:
    pass

 

 

728x90

댓글 영역