【问题标题】:Why does casting dict_keys as a list not work in pdb? [duplicate]为什么将 dict_keys 转换为列表在 pdb 中不起作用? [复制]
【发布时间】:2018-10-14 19:14:09
【问题描述】:

按照post 的规范建议,我正在尝试将我的dict_keys 对象转换为列表。它在 python 3.6.5 解释器中工作得很好。但是,当我在pdb 中执行此操作时,它不起作用。例如

>>> import pdb; pdb.set_trace()
--Return--
<function save_history at 0x100369e18>
> <stdin>(1)<module>()->None
(Pdb) newdict = dict()
(Pdb) newdict["pig"] = "pink"
(Pdb) newdict["finch"] = "yellow"
(Pdb) newdict.keys()
dict_keys(['pig', 'finch'])
(Pdb) list(newdict.keys())
*** Error in argument: '(newdict.keys())'

如何让它在pdb 中工作?

【问题讨论】:

  • 不是重复的。见编辑。
  • python 3 只需添加括号print(list(newdict.keys())) 并查看second answer
  • 好的。确实有效

标签: python python-3.x dictionary pdb


【解决方案1】:

list 是一个 pdb 命令,用于列出文件的源代码: https://docs.python.org/3.6/library/pdb.html#pdbcommand-list

要转义 pdb 命令,您可以这样调用它:

(Pdb) !list(newdict.keys())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-11
    • 1970-01-01
    • 2021-02-15
    • 1970-01-01
    • 1970-01-01
    • 2014-01-23
    相关资源
    最近更新 更多