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

Python入门者遇inquirer库问题:无法选药品且RDV重复显示

解决Python inquirer列表选择异常问题

问题根源及修复方案:

  • 避免使用内置关键字作为变量名:你用了list作为变量名,这是Python内置的列表类型,会覆盖原内置函数,导致inquirer组件调用异常。把变量名改成非关键字,比如prompt_list。
  • 检查并升级inquirer版本:旧版本的inquirer可能存在List组件的渲染bug,执行命令升级:
    pip install --upgrade inquirer
    
  • 调整choices参数格式:虽然元组格式合法,但换成列表格式能避免部分兼容性问题,将choices=("RDV", "MOL", "TCZ", "DEX")改为choices=["RDV", "MOL", "TCZ", "DEX"]。

修正后的完整代码:

import inquirer

prompt_list = [inquirer.List(
    "Medicine",
    message="Choose from the given list",
    choices=["RDV", "MOL", "TCZ", "DEX"],
),]

answer = inquirer.prompt(prompt_list)

print(answer["Medicine"])

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 13:54:52