rest25/library/unicodedata.rst => rest262/library/unicodedata.rst
11
12.. index::
13   single: Unicode
14   single: character
15   pair: Unicode; database
16
17This module provides access to the Unicode Character Database which defines
18character properties for all Unicode characters. The data in this database is
n19-based on the :file:`UnicodeData.txt` file version 4.1.0 which is publicly
n19+based on the :file:`UnicodeData.txt` file version 5.1.0 which is publicly
20-available from `<ftp://ftp.unicode.org/>`_.
20+available from ftp://ftp.unicode.org/.
21
22The module uses the same names and symbols as defined by the UnicodeData File
n23-Format 4.1.0 (see `<http://www.unicode.org/Public/4.1.0/ucd/UCD.html>`_).  It
n23+Format 5.1.0 (see http://www.unicode.org/Public/5.1.0/ucd/UCD.html).  It defines
24-defines the following functions:
24+the following functions:
25
26
27.. function:: lookup(name)
28
29   Look up character by name.  If a character with the given name is found, return
30   the corresponding Unicode character.  If not found, :exc:`KeyError` is raised.
31
32
102
103   Return the normal form *form* for the Unicode string *unistr*. Valid values for
104   *form* are 'NFC', 'NFKC', 'NFD', and 'NFKD'.
105
106   The Unicode standard defines various normalization forms of a Unicode string,
107   based on the definition of canonical equivalence and compatibility equivalence.
108   In Unicode, several characters can be expressed in various way. For example, the
109   character U+00C7 (LATIN CAPITAL LETTER C WITH CEDILLA) can also be expressed as
n110-   the sequence U+0043 (LATIN CAPITAL LETTER C) U+0327 (COMBINING CEDILLA).
n110+   the sequence U+0327 (COMBINING CEDILLA) U+0043 (LATIN CAPITAL LETTER C).
111
112   For each character, there are two normal forms: normal form C and normal form D.
113   Normal form D (NFD) is also known as canonical decomposition, and translates
114   each character into its decomposed form. Normal form C (NFC) first applies a
115   canonical decomposition, then composes pre-combined characters again.
116
117   In addition to these two forms, there are two additional normal forms based on
118   compatibility equivalence. In Unicode, certain characters are supported which
120   NUMERAL ONE) is really the same thing as U+0049 (LATIN CAPITAL LETTER I).
121   However, it is supported in Unicode for compatibility with existing character
122   sets (e.g. gb2312).
123
124   The normal form KD (NFKD) will apply the compatibility decomposition, i.e.
125   replace all compatibility characters with their equivalents. The normal form KC
126   (NFKC) first applies the compatibility decomposition, followed by the canonical
127   composition.
n128+ 
129+   Even if two unicode strings are normalized and look the same to
130+   a human reader, if one has combining characters and the other
131+   doesn't, they may not compare equal.
128
129   .. versionadded:: 2.3
130
131In addition, the module exposes the following constant:
132
133
134.. data:: unidata_version
135
141.. data:: ucd_3_2_0
142
143   This is an object that has the same methods as the entire module, but uses the
144   Unicode database version 3.2 instead, for applications that require this
145   specific version of the Unicode database (such as IDNA).
146
147   .. versionadded:: 2.5
148
n149-Examples::
n153+Examples:
150
n155+   >>> import unicodedata
151   >>> unicodedata.lookup('LEFT CURLY BRACKET')
152   u'{'
153   >>> unicodedata.name(u'/')
154   'SOLIDUS'
155   >>> unicodedata.decimal(u'9')
156   9
157   >>> unicodedata.decimal(u'a')
158   Traceback (most recent call last):
159     File "<stdin>", line 1, in ?
160   ValueError: not a decimal
161   >>> unicodedata.category(u'A')  # 'L'etter, 'u'ppercase
t162-   'Lu'   
t167+   'Lu'
163   >>> unicodedata.bidirectional(u'\u0660') # 'A'rabic, 'N'umber
164   'AN'
165
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op