Unicode escapes only work in unicode strings, so this
a="\u2026"
is actually a string of 6 characters: ‘\’, ‘u’, ‘2’, ‘0’, ‘2’, ‘6’.
To make unicode out of this, use decode('unicode-escape')
:
a="\u2026"
print repr(a)
print repr(a.decode('unicode-escape'))
## '\\u2026'
## u'\u2026'
More Related Contents:
- UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xa0′ in position 20: ordinal not in range(128)
- Python – ‘ascii’ codec can’t decode byte
- What is the difference between encode/decode?
- Why does ENcoding a string result in a DEcoding error (UnicodeDecodeError)?
- What exactly do “u” and “r” string flags do, and what are raw string literals?
- What does the ‘b’ character do in front of a string literal?
- What is the best way to remove accents (normalize) in a Python unicode string?
- How can I concatenate str and int objects?
- Convert a Unicode string to a string in Python (containing extra symbols)
- How to get string objects instead of Unicode from JSON?
- Writing Unicode text to a text file?
- SyntaxError: Non-ASCII character ‘\xa3’ in file when function returns ‘£’
- What exactly do “u” and “r” string prefixes do, and what are raw string literals?
- Why does Python print unicode characters when the default encoding is ASCII?
- Suppress the u’prefix indicating unicode’ in python strings
- Python __str__ versus __unicode__
- General Unicode/UTF-8 support for csv files in Python 2.6
- Printing without newline (print ‘a’,) prints a space, how to remove?
- byte string vs. unicode string. Python
- Python ascii utf unicode
- How do convert unicode escape sequences to unicode characters in a python string
- What does ‘u’ mean in a list?
- Read Unicode characters from command-line arguments in Python 2.x on Windows
- How is unicode represented internally in Python?
- How do I get str.translate to work with Unicode strings?
- How to detect string byte encoding?
- Printing a string prints ‘u’ before the string in Python?
- Python returns length of 2 for single Unicode character string
- SQLite, python, unicode, and non-utf data
- What is internal representation of string in Python 3.x