【问题标题】:Interactive mode breaks with "TypeError: exec() globals must be a dict, not builtin_function_or_method"交互模式因“TypeError: exec() globals must be a dict, not builtin_function_or_method\”而中断
【发布时间】:2022-08-22 23:22:55
【问题描述】:

使用此代码

import code
# ... some code

code.interact(local=locals)

我在 Python Shell 中键入所有内容后都会收到错误消息:

(InteractiveConsole)
>>> 1+1
TypeError: exec() globals must be a dict, not builtin_function_or_method
>>> print(\"nothing works\")
TypeError: exec() globals must be a dict, not builtin_function_or_method

    标签: python


    【解决方案1】:

    我忘了locals 是一个函数,所以我需要写:

    code.interact(local=locals())
    

    而不是我的错误:

    code.interact(local=locals)
    

    【讨论】:

      猜你喜欢
      • 2018-12-23
      • 2013-09-26
      • 2019-12-29
      • 1970-01-01
      • 2022-11-16
      • 2016-06-17
      • 1970-01-01
      • 2021-07-26
      • 2012-12-04
      相关资源
      最近更新 更多