Python でUTF-8, shift_jis, euc_jp,など日本語を使う方法

ここ最近、サイトが無くなって困ったことがあったので記事にしておく

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import codecs

fout = codecs.open('sjis.txt', 'w', 'shift_jis')
fout.write("abcdefg")
fout.close()

#または
fin  = codecs.open('utf_8.txt', 'r', 'utf_8')
file_txt = fin.read()
file_Arr = setting_file_txt.split("\n")

参考

https://osksn2.hep.sci.osaka-u.ac.jp/~taku/osx/python/encoding.html

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です