Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import unicodedata
- inputtext = 'UDON001' # 半角全角混じりでもOK
- menu = 'menu.csv'
- # ひらがな・カタカナ・漢字があるかどうかチェック。 あったらTRUE
- def isJPN(string):
- for ch in string:
- name = unicodedata.name(ch)
- if "CJK UNIFIED" in name \
- or "HIRAGANA" in name \
- or "KATAKANA" in name:
- return True
- return False
- def main():
- if isJPN(inputtext.decode('utf-8')) is False: # 英数字のみなら
- text = unicodedata.normalize('NFKC', inputtext.decode('utf-8')) # 全角をすべて半角に変更
- with open(menu, 'r') as readf: # Menuファイルを開く
- for line in readf: # 1行づつ
- if line.find((text.upper() + ',').encode('utf-8')) == 0: # 先頭からテキストが一致して、その直後に','があったら
- itemname = line[:-1] # その行を取得
- print(itemname)
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment