unicodedata --- پایگاه داده یونیکد¶
This module provides access to the Unicode Character Database (UCD) which defines character properties for all Unicode characters. The data contained in this database is compiled from the UCD version 17.0.0.
The module uses the same names and symbols as defined by Unicode Standard Annex #44, "Unicode Character Database".
همچنین ملاحظه نمائید
برای اطلاعات بیشتر دربارهی یونیکد و چگونگی استفاده از این ماژول، راهنمای عملی یونیکد را ببینید.
Lookup |
|
Look up character by name |
|
Return the name assigned to a character |
|
Numeric values |
|
Decimal value of a character |
|
Digit value of a character |
|
Numeric value of a character |
|
Properties |
|
Bidirectional class of a character |
|
Unicode block of a character |
|
General category of a character |
|
Canonical combining class of a character |
|
Character decomposition mapping |
|
East Asian width of a character |
|
Check if a character has the Extended_Pictographic property |
|
Grapheme_Cluster_Break property of a character |
|
Indic_Conjunct_Break property of a character |
|
Check if a character is a valid identifier continuation |
|
Check if a character is a valid identifier start |
|
Mirrored property of a character |
|
Normalization |
|
Return the normalized form of a string |
|
Check if a Unicode string is normalized |
|
Text segmentation |
|
Iterate over grapheme clusters in a string |
|
- unicodedata.lookup(name, /)¶
جستوجوی نویسه بر اساس نام. اگر نویسهای با نام دادهشده پیدا شود، نویسه متناظر برگردانده میشود. اگر پیدا نشود،
KeyErrorپرتاب میشود. برای مثال:>>> unicodedata.lookup('LEFT CURLY BRACKET') '{'
نویسههای برگرداندهشده توسط این تابع همان نویسههایی هستند که توسط دنباله خنثیسازی
\Nدر رشتههای لفظی تولید میشوند. برای مثال:>>> unicodedata.lookup('MIDDLE DOT') == '\N{MIDDLE DOT}' True
- unicodedata.name(chr, default=None, /)¶
نام اختصاصیافته به نویسه chr را بهصورت یک رشته برمیگرداند. اگر هیچ نامی تعریف نشده باشد، default برگردانده میشود، یا اگر داده نشده باشد،
ValueErrorپرتاب میشود. برای مثال:>>> unicodedata.name('½') 'VULGAR FRACTION ONE HALF' >>> unicodedata.name('\uFFFF', 'fallback') 'fallback'
- unicodedata.decimal(chr, default=None, /)¶
مقدار دهدهی تعیینشده برای نویسه chr را بهصورت عدد صحیح برمیگرداند. اگر چنین مقداری تعریفنشده باشد، default بازگردانده میشود، یا، اگر داده نشده باشد،
ValueErrorپرتاب میشود. برای مثال:>>> unicodedata.decimal('\N{ARABIC-INDIC DIGIT NINE}') 9 >>> unicodedata.decimal('\N{SUPERSCRIPT NINE}', -1) -1
- unicodedata.digit(chr, default=None, /)¶
مقدار رقمی اختصاصیافته به نویسه chr را بهصورت عدد صحیح برمیگرداند. اگر چنین مقداری تعریف نشده باشد، default برگردانده میشود، یا اگر داده نشده باشد،
ValueErrorپرتاب میشود:>>> unicodedata.digit('\N{SUPERSCRIPT NINE}') 9
- unicodedata.numeric(chr, default=None, /)¶
مقدار عددی اختصاصیافته به نویسه chr را بهصورت float برمیگرداند. اگر چنین مقداری تعریفنشده باشد، default برگردانده میشود، یا اگر داده نشده باشد،
ValueErrorپرتاب میشود:>>> unicodedata.numeric('½') 0.5
- unicodedata.category(chr, /)¶
Returns the general category assigned to the character chr as string. General category names consist of two letters. See the General Category Values section of the Unicode Character Database documentation for a list of category codes. For example:
>>> unicodedata.category('A') # 'L'etter, 'u'ppercase 'Lu'
- unicodedata.bidirectional(chr, /)¶
Returns the bidirectional class assigned to the character chr as string. If no such value is defined, an empty string is returned. See the Bidirectional Class Values section of the Unicode Character Database documentation for a list of bidirectional codes. For example:
>>> unicodedata.bidirectional('\N{ARABIC-INDIC DIGIT SEVEN}') # 'A'rabic, 'N'umber 'AN'
- unicodedata.combining(chr, /)¶
Returns the canonical combining class assigned to the character chr as integer. Returns
0if no combining class is defined. See the Canonical Combining Class Values section of the Unicode Character Database for more information.
- unicodedata.east_asian_width(chr, /)¶
Returns the east asian width assigned to the character chr as string. For a list of widths and or more information, see the Unicode Standard Annex #11.
- unicodedata.block(chr, /)¶
Returns the block assigned to the character chr. For example:
>>> unicodedata.block('S') 'Basic Latin'
اضافه شده در نسخهی 3.15.
- unicodedata.mirrored(chr, /)¶
ویژگی آینهای اختصاصیافته به نویسهی chr را بهصورت عدد صحیح بازمیگرداند. اگر نویسه بهعنوان نویسهی «آینهای» در متن دوجهته شناسایی شده باشد،
1و در غیر این صورت0بازمیگرداند. برای مثال:>>> unicodedata.mirrored('>') 1
- unicodedata.isxidstart(chr, /)¶
Return
Trueif chr is a valid identifier start per the Unicode Standard Annex #31, that is, it has theXID_Startproperty. ReturnFalseotherwise. For example:>>> unicodedata.isxidstart('S') True >>> unicodedata.isxidstart('0') False
اضافه شده در نسخهی 3.15.
- unicodedata.isxidcontinue(chr, /)¶
Return
Trueif chr is a valid identifier character per the Unicode Standard Annex #31, that is, it has theXID_Continueproperty. ReturnFalseotherwise. For example:>>> unicodedata.isxidcontinue('S') True >>> unicodedata.isxidcontinue(' ') False
اضافه شده در نسخهی 3.15.
- unicodedata.decomposition(chr, /)¶
نگاشت تجزیهی نویسهای را که به نویسهی chr اختصاصیافته است، بهصورت رشته برمیگرداند. در صورتی که چنین نگاشتی تعریفنشده باشد، یک رشتهی خالی برگردانده میشود. برای مثال:
>>> unicodedata.decomposition('Ã') '0041 0303'
- unicodedata.grapheme_cluster_break(chr, /)¶
Returns the Grapheme_Cluster_Break property assigned to the character.
اضافه شده در نسخهی 3.15.
- unicodedata.indic_conjunct_break(chr, /)¶
Returns the Indic_Conjunct_Break property assigned to the character.
اضافه شده در نسخهی 3.15.
- unicodedata.extended_pictographic(chr, /)¶
Returns
Trueif the character has the Extended_Pictographic property,Falseotherwise.اضافه شده در نسخهی 3.15.
- unicodedata.normalize(form, unistr, /)¶
فرم نرمال form را برای رشتهی یونیکدی unistr برمیگرداند. مقادیر معتبر برای form عبارتاند از 'NFC'، 'NFKC'، 'NFD' و 'NFKD'.
استاندارد یونیکد اشکال مختلف نرمالسازی برای یک رشتهی یونیکد را بر پایهی تعریف همارزی کانونیکال و همارزی سازگاری تعریف میکند. در یونیکد، میتوان چندین نویسه را به روشهای مختلفی بیان کرد. برای مثال، نویسهی U+00C7 (LATIN CAPITAL LETTER C WITH CEDILLA) همچنین میتواند بهصورت دنبالهی U+0043 (LATIN CAPITAL LETTER C) U+0327 (COMBINING CEDILLA) بیان شود.
برای هر نویسه، دو فرم عادی وجود دارد: فرم عادی C و فرم عادی D. فرم عادی D (NFD) همچنین با عنوان تجزیهی کانونیکال (canonical decomposition) شناخته میشود و هر نویسه را به فرم تجزیهشدهی آن تبدیل میکند. فرم عادی C (NFC) ابتدا یک تجزیهی کانونیکال (canonical decomposition) اعمال میکند، سپس نویسههای از پیش ترکیبشده را دوباره ترکیب میکند.
علاوه بر این دو صورت، دو صورت نرمال دیگر نیز بر پایهی همارزی سازگاری وجود دارد. در یونیکد، از برخی نویسهها پشتیبانی میشود که بهطور معمول با نویسههای دیگر یکسانسازی میشدند. برای مثال، U+2160 (ROMAN NUMERAL ONE) در واقع همان U+0049 (LATIN CAPITAL LETTER I) است. با این حال، این نویسه در یونیکد برای سازگاری با مجموعهنویسههای موجود (برای مثال، gb2312) پشتیبانی میشود.
فرم نرمال KD (NFKD) تجزیهی سازگاری (compatibility decomposition) را اعمال میکند، یعنی همهی نویسههای سازگاری را با معادلهایشان جایگزین میکند. فرم نرمال KC (NFKC) ابتدا تجزیهی سازگاری را اعمال میکند و سپس ترکیب کانونیکال (canonical composition) را انجام میدهد.
حتی اگر دو رشتهی یونیکد نرمالشده باشند و برای خوانندهی انسانی یکسان به نظر برسند، اگر یکی دارای نویسههای ترکیبی باشد و دیگری نداشته باشد، ممکن است مقایسهی آنها برابر نباشد.
- unicodedata.is_normalized(form, unistr, /)¶
بازمیگرداند که آیا رشتهی یونیکد unistr در فرم نرمال form قرار دارد یا خیر. مقادیر معتبر برای form عبارتاند از 'NFC'، 'NFKC'، 'NFD' و 'NFKD'.
اضافه شده در نسخهی 3.8.
- unicodedata.iter_graphemes(unistr, start=0, end=sys.maxsize, /)¶
Returns an iterator to iterate over grapheme clusters. With optional start, iteration begins at that position. With optional end, iteration stops at that position.
Converting an emitted item to string returns a substring corresponding to the grapheme cluster. Its
startandendattributes denote the start and end of the grapheme cluster.It uses extended grapheme cluster rules defined by Unicode Standard Annex #29, "Unicode Text Segmentation".
اضافه شده در نسخهی 3.15.
In addition, the module exposes the following constants:
- unicodedata.unidata_version¶
نسخهی پایگاه دادهی یونیکد استفادهشده در این ماژول.
- unicodedata.ucd_3_2_0¶
This is an object that has most of the methods of the entire module, but uses the Unicode database version 3.2 instead, for applications that require this specific version of the Unicode database (such as IDNA).
پانویسها