python代码中含'''xxx'''注释报(unicode error) 'utf-8' codec can't decode错误

代码中含有’’‘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)保存文件后,重新打开文件执行即解决

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值