代码中含有’’‘xxx’’'注释时,geany编辑器已经设置成编码未utf-8,但是执行时提示不能utf-8 decode
源代码:
-- coding:utf-8 --
import json
‘’‘定义输入你最喜欢的数字函数并存入文件中’’’
def input_num(file_path):
number = input(“your favorite number:”)
with open(file_path,‘w’,encoding=‘utf-8-sig’) as f_object:
json.dump(number,f_object)
‘’‘读入文件中存的最喜欢数字’’’
def read_num(file_path):
try:
with open(file_path,‘r’,encoding=‘utf-8-sig’) as f_object:
content = json.load(f_object)
except FileNotFount:
print(“未找到该文件”)
else:
print(content)
input_num(‘hello.json’)
执行时报错:
解决方案:
文件用notepad打开,点击 菜单栏Encoding(编码)>> Convert to UTF-8(转化成utf-8)保存文件后,重新打开文件执行即解决