當前位置: 首頁>>代碼示例>>Python>>正文


Python Character.get_utf8方法代碼示例

本文整理匯總了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
開發者ID:titeipa,項目名稱:CharacterClassifier,代碼行數:39,代碼來源:charcol.py


注:本文中的tegaki.character.Character.get_utf8方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。