You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2014-10-11.17:58:45.231>labels= ['type-feature', 'expert-unicode']
title='Add block info to unicodedata'updated_at=<Date2015-10-17.07:47:47.945>user='https://github.com/flying-sheep'
The repo https://github.com/nagisa/unicodeblocks contains pretty much the functionality i’d like to see: a way to get access to information about all blocks, and a way to get the block name a char is in.
I propose to include something very similar to those two APIs in unicodedata:
unicodedata.Block: class with start, end, and name property.
its __contains__ should work for single-char-strings (which tests if that char is in the block) and for ints (which tests if the codepoint is in the block)
maybe make it iterable over its chars?
unicodedata.blocks: OrderedDict of str (block name) → Block object mappings ordered by Block.start.
then blocks.keys() would yield the names in order, and blocks.values() the block objects in order.
unicodedata.block_of(chr, name_only=False): returns the Block object for which “chr in block” is True, or its name.
---
alternative: make the Block class an unfancy namedtuple without __contains__ method.
---
Together with bpo-18234, fixing this bug will complete UnicodeData support in python, i guess.
I needed this in the past and had to implement it myself, so adding it to unicodedata might be OK. A script to generate the list of blocks from the official Unicode files should probably be created and used whenever we update the version of the Unicode database.
Activity
flying-sheep commentedon Oct 11, 2014
See also bpo-6331.
The repo https://github.com/nagisa/unicodeblocks contains pretty much the functionality i’d like to see: a way to get access to information about all blocks, and a way to get the block name a char is in.
I propose to include something very similar to those two APIs in unicodedata:
unicodedata.Block: class with start, end, and name property.
its __contains__ should work for single-char-strings (which tests if that char is in the block) and for ints (which tests if the codepoint is in the block)
maybe make it iterable over its chars?
unicodedata.blocks: OrderedDict of str (block name) → Block object mappings ordered by Block.start.
then blocks.keys() would yield the names in order, and blocks.values() the block objects in order.
unicodedata.block_of(chr, name_only=False): returns the Block object for which “chr in block” is True, or its name.
---
alternative: make the Block class an unfancy namedtuple without __contains__ method.
---
Together with bpo-18234, fixing this bug will complete UnicodeData support in python, i guess.
ezio-melotti commentedon Nov 2, 2014
I needed this in the past and had to implement it myself, so adding it to unicodedata might be OK. A script to generate the list of blocks from the official Unicode files should probably be created and used whenever we update the version of the Unicode database.
pythongh-66802: Add `unicodedata.block()` function (python#145042)
pythongh-66802: Add `unicodedata.block()` function (python#145042)
pythongh-66802: Add `unicodedata.block()` function (python#145042)