codeを書いていると必ずエラーが出ます。すべて自分の浅学のせいですので、よく出るエラーを書いておきます。
#➊ tabで区切った次のようなtxtファイルを読むときによく発生します。
with open('四文字熟語.txt') as file:
for i in list:
words = i.split('\t') #tab区切りの場合に必要
word_list.append(words)
対策:encoding="utf-8_sig"を追加すると治ることが多い(fileの属性次第)
with open('四文字熟語.txt','r', encoding="utf-8_sig") as file:
for line in file:
# print(line, end='') # 改行なし
print(line) # 改行あり
コメント