unicode-literals

Python unicode string literals :: what's the difference between '\u0391' and u'\u0391'

耗尽温柔 提交于 2021-02-20 09:40:33
问题 I am using Python 2.7.3. Can anybody explain the difference between the literals: '\u0391' and: u'\u0391' and the different way they are echoed in the REPL below (especially the extra slash added to a1): >>> a1='\u0391' >>> a1 '\\u0391' >>> type(a1) <type 'str'> >>> >>> a2=u'\u0391' >>> a2 u'\u0391' >>> type(a2) <type 'unicode'> >>> 回答1: You can only use unicode escapes ( \uabcd ) in a unicode string literal. They have no meaning in a byte string. A Python 2 Unicode literal ( u'some text' )

Python unicode string literals :: what's the difference between '\u0391' and u'\u0391'

与世无争的帅哥 提交于 2021-02-20 09:37:53
问题 I am using Python 2.7.3. Can anybody explain the difference between the literals: '\u0391' and: u'\u0391' and the different way they are echoed in the REPL below (especially the extra slash added to a1): >>> a1='\u0391' >>> a1 '\\u0391' >>> type(a1) <type 'str'> >>> >>> a2=u'\u0391' >>> a2 u'\u0391' >>> type(a2) <type 'unicode'> >>> 回答1: You can only use unicode escapes ( \uabcd ) in a unicode string literal. They have no meaning in a byte string. A Python 2 Unicode literal ( u'some text' )

Python unicode string literals :: what's the difference between '\u0391' and u'\u0391'

旧城冷巷雨未停 提交于 2021-02-20 09:37:25
问题 I am using Python 2.7.3. Can anybody explain the difference between the literals: '\u0391' and: u'\u0391' and the different way they are echoed in the REPL below (especially the extra slash added to a1): >>> a1='\u0391' >>> a1 '\\u0391' >>> type(a1) <type 'str'> >>> >>> a2=u'\u0391' >>> a2 u'\u0391' >>> type(a2) <type 'unicode'> >>> 回答1: You can only use unicode escapes ( \uabcd ) in a unicode string literal. They have no meaning in a byte string. A Python 2 Unicode literal ( u'some text' )

input() and literal unicode parsing

流过昼夜 提交于 2021-01-28 02:01:24
问题 Using input() takes a backslash as a literal backslash so I am unable to parse a string input with unicode. What I mean: Pasting a string like "\uXXXX\uXXXX\uXXXX" into an input() call will become interpreted as "\\uXXXX\\uXXXX\\uXXXX" but I want it read \u as a single character instead of two separate characters. Does anyone know how or if possible to make it happen? Edit: I am taking input as above and converting it to ascii such as below.. import unicodedata def Reveal(unicodeSol):

How do you safely declare a 16-bit string literal in C?

我只是一个虾纸丫 提交于 2020-08-07 03:40:37
问题 I'm aware that there is already a standard method by prefixing with L : wchar_t *test_literal = L"Test"; The problem is that wchar_t is not guaranteed to be 16-bits, but for my project, I need a 16-bit wchar_t . I'd also like to avoid the requirement of passing -fshort-wchar . So, is there any prefix for C (not C++) that will allow me to declare a UTF-16 string literal? 回答1: So, is there any prefix for C (not C++) that will allow me to declare a UTF-16 string literal? Almost, but not quite.

Can I ensure that users that import my Python code use Unicode literals?

笑着哭i 提交于 2020-01-16 18:19:42
问题 My code includes from __future__ import unicode_literals and has many functions that accept (and expect) Unicode strings as input in order to function fully. Is there a way to ensure that users (in scripts, Python, or IPython, etc.) also use Unicode literals so that, for example my_func("AβC") does not cause an error ("ascii' codec can't decode byte 0xce ...") and so that my_func(u"AβC") is not necessary? 回答1: No, unicode_literals is a per-module configuration and must be imported in each and

Unicode (hexadecimal) character literals in MySQL

∥☆過路亽.° 提交于 2020-01-11 02:46:22
问题 Is there a way to specify Unicode character literals in MySQL? I want to replace a Unicode character with an Ascii character, something like the following: Update MyTbl Set MyFld = Replace(MyFld, "ẏ", "y") But I'm using even more obscure characters which are not available in most fonts, so I want to be able to use Unicode character literals, something like Update MyTbl Set MyFld = Replace(MyFld, "\u1e8f", "y") This SQL statement is being invoked from a PHP script - the first form is not only

unicode_literals and doctest in Python 2.7 AND Python 3.5

半城伤御伤魂 提交于 2019-12-30 23:04:34
问题 Consider the following demo script: # -*- coding: utf-8 -*- from __future__ import division from __future__ import unicode_literals def myDivi(): """ This is a small demo that just returns the output of a divison. >>> myDivi() 0.5 """ return 1/2 def myUnic(): """ This is a small demo that just returns a string. >>> myUnic() 'abc' """ return 'abc' if __name__ == "__main__": import doctest extraglobs = {} doctest.testmod(extraglobs=extraglobs) The doctest passes on Python 3.5, but fails on

How to write unicode cross symbol in Java?

心不动则不痛 提交于 2019-12-29 18:36:09
问题 I'm trying to write this unicode cross symbol (𐀵) in Java: class A { public static void main(String[] args) { System.out.println("\u2300"); System.out.println("\u10035"); } } I can write o with a line through it (⌀) just fine, but the cross symbol doesn't show up, instead it just prints the number 5: # javac A.java && java A ⌀ ဃ5 Why? 回答1: You're looking for U+10035, which is outside the Basic Multilingual Plane. That means you can't use \u to specify the value, as that only deals with U+0000

Unicode literals causing invalid syntax

风流意气都作罢 提交于 2019-12-20 01:45:38
问题 The following code: s = s.replace(u"&", u"&") is causing an error in python: SyntaxError: invalid syntax removing the u 's before the " fixes the problem, but this should work as is? I'm using Python 3.1 回答1: The u is no longer used in Python 3. String literals are unicode by default. See What's New in Python 3.0. You can no longer use u"..." literals for Unicode text. However, you must use b"..." literals for binary data. 回答2: On Python 3, strings are unicode. There is no need to (and as you