【问题标题】:unbound method exception when debugging in Visual Studio Code在 Visual Studio Code 中调试时出现未绑定的方法异常
【发布时间】:2018-02-19 18:17:21
【问题描述】:

所以我有这两个文件 test.py 和 translate.py

我正在使用 test.py 使用 translate.py 中的函数翻译单个字符串

问题是我在从 Visual Studio Code 运行 test.py 时遇到了静态类方法上的未绑定方法异常,但它在终端上运行良好。以下是导致问题的 sn-p。两个文件都在同一个文件夹中。

def convertLine(line):
    ...
    # cmd class is defined in translator.py
    cmd = createCmd(line)

    # Verifier.checkCommand is causing the exception 
    if (Verifier.checkCommand(cmd)):
        return True

Class Verifier:

  def checkCommand(cmd):
         # some checks
         Return (true)

【问题讨论】:

  • 有什么异常?您遇到什么错误?
  • @ifconfig 这是运行时引发的异常,表示 Verifier.checkCommand 是一个未绑定的方法。
  • 您的代码必须比您迄今为止发布的更多。这里没有足够的帮助。

标签: linux python-3.x visual-studio-code


【解决方案1】:

我不知道这是否是根本问题。但我发现,如果我用 @staticmethod 装饰器包围静态函数,它会起作用。由此我意识到,VSCode 在运行时使用的是 python2.7,但我的终端使用的是 Python 3.6。因此,在 VSCode 中更改路径设置以执行 Python3.6 后,它正在工作。

【讨论】:

    猜你喜欢
    • 2022-08-05
    • 2021-09-19
    • 1970-01-01
    • 1970-01-01
    • 2019-02-21
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多