기계는 거짓말하지 않는다

Python String u'\ufeff' 본문

Python

Python String u'\ufeff'

KillinTime 2023. 4. 21. 20:25

파일을 읽어올 때 '\ufeff' 문자가 가장 앞에 붙는 경우가 있다.

이로 인해 오류가 발생할 수 있다.

파일을 열 때 utf-8-sig 형식을 이용하거나

저장을 할 때 UTF-8 BOM 인코딩이 아닌 UTF-8 형식으로 다시 저장한다.

f = open('path', 'r', encoding='utf-8-sig')

unicode - u'\ufeff' in Python string - Stack Overflow

 

u'\ufeff' in Python string

I got an error with the following exception message: UnicodeEncodeError: 'ascii' codec can't encode character u'\ufeff' in position 155: ordinal not in range(128) Not sure what u'\ufeff' is, it sh...

stackoverflow.com

 

Comments