복붙노트

[PYTHON] 파이썬 2.7의 문자열에서 유니 코드 \ u2026을 제거하는 중

PYTHON

파이썬 2.7의 문자열에서 유니 코드 \ u2026을 제거하는 중

나는 python2.7에서 이와 같은 문자열을 가지고있다.

 This is some \u03c0 text that has to be cleaned\u2026! it\u0027s annoying!

내가 어떻게 이것을 이걸로 변환 할까?

This is some text that has to be cleaned! its annoying!

해결법

  1. ==============================

    1.

    >>> s
    'This is some \\u03c0 text that has to be cleaned\\u2026! it\\u0027s annoying!'
    >>> print(s.decode('unicode_escape').encode('ascii','ignore'))
    This is some  text that has to be cleaned! it's annoying!
    
  2. from https://stackoverflow.com/questions/15321138/removing-unicode-u2026-like-characters-in-a-string-in-python2-7 by cc-by-sa and MIT license