end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

jaconv , unicodedata for python による 全角→半角変換

#!python3
# -*- coding: utf-8 -*-

import sys
import jaconv           # pip install jaconv
import unicodedata      # 標準module

def main():
    org_file = sys.argv[1]
    print( org_file )

    with open(org_file, 'r', encoding='UTF-8') as f:
        for line in f.readlines():
            line = line.strip()
            cols = line.split("\t")
            new_shop = unicodedata.normalize("NFKC", cols[2])
            new_shop = jaconv.z2h(new_shop, kana=True, ascii=False, digit=False)
            print(cols[2], new_shop)

if __name__ == '__main__':
    main()