python报错,一直改不出来


import os
import csv
import matplotlib.pyplot as plt

# 定义财务记录列表和文件名变量
finas = []
filename = "FinanceInfo.csv"

# 显示主界面
def ShowUI():
    os.system("cls")
    print("********** 财务记录管理系统 **********")
    print("1. 显示财务记录")
    print("2. 添加财务记录")
    print("3. 删除财务记录")
    print("4. 修改财务记录")
    print("5. 分析财务记录")
    print("6. 退出")


# 显示财务记录
def ShowFinaInfo():
    os.system("cls")
    print("********** 财务记录 **********")
    print("{0:<10}{1:<10}{2:<10}{3:<10}{4:<10}"
          "{5:<10}{6:<10}{7:<10}{8:<10}"
          .format("月份", "伙食费", "日杂费", "教育费",
                  "服装费", "医疗费", "交通费", "娱乐费", "交际费"))
    for fina in finas:
        print("{0:<10}{1:<10}{2:<10}{3:<10}{4:<10}"
              "{5:<10}{6:<10}{7:<10}{8:<10}"
              .format(fina["finaMon"], fina["mealCost"], fina["dailyCost"],
                      fina["eduCost"], fina["clothCost"], fina["medCost"],
                      fina["trafCost"], fina["recCost"], fina["comCost"]))


# 添加财务记录
def AddFinaInfo():
    os.system("cls")
    print("********** 添加财务记录 **********")
    fina = {}
    fina["finaMon"] = input("月份:")
    fina["mealCost"] = input("伙食费:")
    fina["dailyCost"] = input("日杂费:")
    fina["eduCost"] = input("教育费:")
    fina["clothCost"] = input("服装费:")
    fina["medCost"] = input("医疗费:")
    fina["trafCost"] = input("交通费:")
    fina["recCost"] = input("娱乐费:")
    fina["comCost"] = input("交际费:")
    finas.append(fina)
    SaveToFile()


# 删除财务记录
def DelFinaInfo():
    os.system("cls")
    print("********** 删除财务记录 **********")
    index = int(input("要删除的记录序号: "))
    if index >= 1 and index <= len(finas):
        finas.pop(index - 1)
        SaveToFile()
    else:
        print("不存在该记录!")


# 修改财务记录
def ModiFinaInfo():
    os.system("cls")
    print("********** 修改财务记录 **********")
    index = int(input("要修改的记录序号: "))
    if index >= 1 and index <= len(finas):
        fina = finas[index - 1]
        fina["mealCost"] = input("伙食费:")
        fina["dailyCost"] = input("日杂费:")
        fina["eduCost"] = input("教育费:")
        fina["clothCost"] = input("服装费:")
        fina["medCost"] = input("医疗费:")
        fina["trafCost"] = input("交通费:")
        fina["recCost"] = input("娱乐费:")
        fina["comCost"] = input("交际费:")
        SaveToFile()
    else:
        print("不存在该记录!")


# 保存财务记录到文件
def SaveToFile():
    with open(filename, mode="w", newline="", encoding="utf-8-sig") as f:
        writer = csv.DictWriter(f, fieldnames=["finaMon", "mealCost",
                                               "dailyCost", "eduCost",
                                               "clothCost", "medCost",
                                               "trafCost", "recCost",
                                               "comCost"])
        writer.writeheader()
        for fina in finas:
            writer.writerow(fina)


# 读取财务记录文件
def LoadFromFile():
    if not os.path.exists(filename):
        return
    with open(filename, mode="r", newline="", encoding="utf-8-sig") as f:
        reader = csv.DictReader(f)
        for row in reader:
            fina = {}
            fina["finaMon"] = row["finaMon"]
            fina["mealCost"] = row["mealCost"]
            fina["dailyCost"] = row["dailyCost"]
            fina["eduCost"] = row["eduCost"]
            fina["clothCost"] = row["clothCost"]
            fina["medCost"] = row["medCost"]
            fina["trafCost"] = row["trafCost"]
            fina["recCost"] = row["recCost"]
            fina["comCost"] = row["comCost"]
            finas.append(fina)


# 分析财务记录
def AnalyFinaInfo():
    os.system("cls")
    print("********** 分析财务记录 **********")
    # 在此处添加利用Matplotlib进行数据分析的代码


# 程序主流程
def main():
    LoadFromFile()
    while True:
        ShowUI()
        choice = input("请选择功能(输入数字):")
        if choice == "1":
            ShowFinaInfo()
            input("按任意键继续...")
        elif choice == "2":
            AddFinaInfo()
        elif choice == "3":
            DelFinaInfo()
        elif choice == "4":
            ModiFinaInfo()
        elif choice == "5":
            AnalyFinaInfo()
        elif choice == "6":
            break
        else:
            print("无效选项,请重新输入!")

if __name__ == '__main__':
    main()

我的运行代码是这样的,但是它给我报错,已经改了很多遍了,已经改废了,帮帮忙吧
报错的是这样:

Traceback (most recent call last):
  File "E:\xiazaiwenjian\FinanceInfo.csv\家庭财务分析系统.py", line 150, in 
    main()
  File "E:\xiazaiwenjian\FinanceInfo.csv\家庭财务分析系统.py", line 129, in main
    LoadFromFile()
  File "E:\xiazaiwenjian\FinanceInfo.csv\家庭财务分析系统.py", line 106, in LoadFromFile
    for row in reader:
  File "C:\Python38\lib\csv.py", line 110, in __next__
    self.fieldnames
  File "C:\Python38\lib\csv.py", line 97, in fieldnames
    self._fieldnames = next(self.reader)
  File "C:\Python38\lib\codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
  File "C:\Python38\lib\encodings\utf_8_sig.py", line 69, in _buffer_decode
    return codecs.utf_8_decode(input, errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd4 in position 1: invalid continuation byte
>>> 

你确认文件编码是utf-8-sig吗?

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd4 in position 1: invalid continuation byte

你这个报错提示,就是解码异常了

我记得这个问题可以在GPT里面解决,这个事情你把代码放进去,然后在几个不同的平台里面解释一下这个错误

很抱歉听到您遇到了这个报错,但是我不确定您具体是在哪里出现了问题。如果您能够提供更多的上下文和代码,我会尽力帮助您解决问题。 一般来说,这个报错通常是由于您在使用Python的内置函数(如`print`)时,调用了错误的函数或者使用了错误的语法导致的。您可以尝试检查您的代码中是否存在语法错误或者调用了错误的函数。另外,您也可以尝试升级您的Python版本,或者使用其他版本的Python来解决这个问题。 如果您的代码已经修改了,但仍然无法解决问题,您可以尝试重新运行您的代码,或者查看错误消息中的详细信息,以获取更多的帮助。如果您无法解决问题,请考虑咨询您的编程导师或者Python社区中其他开发者,以获取更进一步的帮助。