Guest User

Untitled

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