- 파이썬 2.7 인코딩 에러 해결
(UnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 in position 0: ordinal)
스크립트 첫줄에 파일의 인코딩을 명시
#-*- coding: utf-8 -*-
- C:\Python27\Lib\site.py
- Encoding utf-8 수정
def setencoding(): """Set the string encoding used by the Unicode implementation. The default is 'ascii', but if you're willing to experiment, you can change this.""" encoding = "utf-8" # Default value set by _PyUnicode_Init() # 요기! if 0: # Enable to support locale aware default string encodings. import locale loc = locale.getdefaultlocale() if loc[1]: encoding = loc[1] if 0: # Enable to switch off string to Unicode coercion and implicit # Unicode to string conversion. encoding = "undefined" if encoding != "utf-8": # 요기! # On Non-Unicode builds this will raise an AttributeError... sys.setdefaultencoding(encoding) # Needs Python Unicode build !
- C:\Python27\Lib\ntpath.py
***p_path
를p_path.encode('utf-8')
로 치환해준다.***
.... elif p_drive and p_drive != result_drive: if p_drive.lower() != result_drive.lower(): # Different drives => ignore the first path entirely result_drive = p_drive result_path = p_path continue # Same drive in different case result_drive = p_drive # Second path is relative to the first if result_path and result_path[-1] not in '\\\\/': result_path = result_path + '\\\\' result_path = result_path + p_path.encode('utf-8') # 요기! ## add separator between UNC and non-absolute path if (result_path and result_path[0] not in '\\\\/' and result_drive and result_drive[-1:] != ':'): return result_drive + sep + result_path return result_drive + result_pat
'Engineering WIKI > Python' 카테고리의 다른 글
[Python] shutil 함수 (0) | 2019.07.03 |
---|---|
[Python] 객체와 인스턴스의 차이 (0) | 2019.07.03 |
[Python] 파이썬2,3 동시사용 (0) | 2019.07.02 |
[Python] is 와 ==의 차이점 (0) | 2019.05.30 |
[Python] string 모듈 (0) | 2019.05.27 |
[Python] tkinter 사용 (0) | 2019.02.14 |
[Python] 엑셀 코드(xlsx 파일 만들기) (0) | 2018.10.15 |
[Python]Using Python file in Shell Script [ 쉘 스크립트 내에서 파이썬 프로그램 실행 ] (0) | 2018.08.05 |