本文整理汇总了Python中tegaki.character.Character.get_utf8方法的典型用法代码示例。如果您正苦于以下问题:Python Character.get_utf8方法的具体用法?Python Character.get_utf8怎么用?Python Character.get_utf8使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tegaki.character.Character
的用法示例。
在下文中一共展示了Character.get_utf8方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_character_directory
# 需要导入模块: from tegaki.character import Character [as 别名]
# 或者: from tegaki.character.Character import get_utf8 [as 别名]
def from_character_directory(directory,
extensions=["xml", "bz2", "gz"],
recursive=True,
check_duplicate=False):
"""
Creates a character collection from a directory containing
individual character files.
"""
regexp = re.compile("\.(%s)$" % "|".join(extensions))
charcol = CharacterCollection()
for name in os.listdir(directory):
full_path = os.path.join(directory, name)
if os.path.isdir(full_path) and recursive:
charcol += CharacterCollection.from_character_directory(
full_path, extensions)
elif regexp.search(full_path):
char = Character()
gzip = False;
bz2 = False
if full_path.endswith(".gz"): gzip = True
if full_path.endswith(".bz2"): bz2 = True
try:
char.read(full_path, gzip=gzip, bz2=bz2)
except ValueError:
continue # ignore malformed XML files
utf8 = char.get_utf8()
if utf8 is None: utf8 = "Unknown"
charcol.add_set(utf8)
if not check_duplicate or \
not char in charcol.get_characters(utf8):
charcol.append_character(utf8, char)
return charcol