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

调用getpass()提示positional arguments过多的技术求助

解决getpass参数错误问题
  • 错误原因:getpass函数(你用hinput作为别名)最多接受2个位置参数,但你传入了3个("Enter"、p1、"choice: "),触发了TypeError。getpass的第一个参数需要是完整的提示字符串,不能拆分多个参数传递。

  • 修正后的代码:
    把提示内容拼接成单个字符串即可,推荐用f-string(Python 3.6+支持):

    from getpass import getpass as hinput
    # 确保p1已经被定义为玩家的名字(比如p1 = input("Enter player 1 name: "))
    ch1 = hinput(f"Enter {p1} choice: ")
    

    也可以用传统字符串拼接:

    ch1 = hinput("Enter " + p1 + " choice: ")
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 03:01:07