You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python调用reading_in()时报错缺少必需位置参数'surname1'求助

问题原因

  • 函数定义和调用的参数数量不匹配:你定义的reading_in函数要求传入2个位置参数name1、surname1,但实际调用时仅传入了1个plans参数,因此触发参数缺失的类型错误。
  • 你定义的name1、surname1两个形参在函数内部完全没有被使用,属于冗余定义,没有实际作用。
  • 额外注意:你函数内部用到的plans变量当前是读取全局变量,逻辑上也建议通过参数传入更规范。

修复方案

直接修改函数定义,删掉冗余参数,改为接收需要用到的plans参数即可,同时推荐使用with语句管理文件IO,避免手动调用close()可能出现的资源泄漏问题:

# 修改后的读取函数定义
def reading_in(plans):  
    with open("customer_plan.csv","r") as in_file_obj:
        line = in_file_obj.readline()
        while line != "":
            fields = line.strip().split(",")
            plan_index = int(fields[0])
            name = fields[1]
            surname = fields[2]
            name_surname = name + " " + surname
            backend.add_plan(plans[plan_index], name_surname)
            line = in_file_obj.readline()

原调用代码backend.reading_in(plans)无需调整,修改后即可正常运行。

内容的提问来源于stack exchange,提问作者tim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 19:36:02