티스토리 뷰
python
[python][error] 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UX 오류 수정
hs_seo 2017. 1. 23. 15:41'unicodeescape' codec can't decode bytes in position 2-3: truncated \U
파이썬에서 파일을 읽기 위하여 파일의 경로를 지정하는 도중에
경로상에 \u, \U 가 있으면 위와 같은 오류가 발생한다.
파이썬은 특수 문자를 \ 로 시작하여 인식하기 때문에 위와 같은 오류가 발생한다.
특수 문자 목록은 다음과 같다.
* \u, \U는 유니코드를 나타내는 특수 문자이다.
Escape Sequence | Meaning | Notes |
---|---|---|
\newline | Ignored | |
\\ | Backslash (\ ) | |
\' | Single quote (' ) | |
\" | Double quote (" ) | |
\a | ASCII Bell (BEL) | |
\b | ASCII Backspace (BS) | |
\f | ASCII Formfeed (FF) | |
\n | ASCII Linefeed (LF) | |
\N{name} | Character named name in the Unicode database (Unicode only) | |
\r | ASCII Carriage Return (CR) | |
\t | ASCII Horizontal Tab (TAB) | |
\uxxxx | Character with 16-bit hex value xxxx (Unicode only) | (1) |
\Uxxxxxxxx | Character with 32-bit hex value xxxxxxxx (Unicode only) | (2) |
\v | ASCII Vertical Tab (VT) | |
\ooo | Character with octal value ooo | (3,5) |
\xhh | Character with hex value hh | (4,5) |
해결방법은 \를 \\ 로 수정하여 처리하는 방법이 있고,
다른 방법은 만자열 앞에 'r'을 붙여 주면 된다. (문자열을 해석하지 않고 raw 로 읽기 위한 지시자이다.)
아래와 같이 수정해 주면 된다.
1) "C:\User" -> "C:\\User"
2) "C:\User" -> r"C:\User"
반응형
'python' 카테고리의 다른 글
[python] 문자열을 효율적으로 concat 하는 방법 (0) | 2017.02.22 |
---|---|
[python] range, xrange 함수 사용법 (1) | 2017.02.22 |
[python][error] PermissionError: [Errno 13] Permission denied: ... (1) | 2017.01.23 |
[python] yield 커맨드(iterable, generator) (0) | 2016.12.16 |
[python][pip] pip 인스톨시에 프록시, 인증서 이용하기 (0) | 2016.12.15 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- error
- 오류
- 정올
- java
- Hadoop
- 하이브
- build
- 파이썬
- SPARK
- 백준
- 알고리즘
- ubuntu
- hbase
- HDFS
- 하둡
- airflow
- SQL
- 다이나믹
- S3
- AWS
- Linux
- Tez
- nodejs
- yarn
- bash
- oozie
- Python
- mysql
- emr
- HIVE
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함