我是Python编程新手。我使用 Visual Studio 代码。我的调试器有一些问题。当我调试脚本时,我的调试器会按照应有的方式在脚本中的断点处进行中断。但在我的脚本中,我还从类创建对象。为了调试类的方法(从类创建的对象),我在方法中设置了断点。 我希望调试器跳转到那里并尊重断点,但这并没有发生。我的代码很长,所以我尝试缩短它。因此,在我的代码示例中,我在步骤(old_state,action)的方法定义内设置了一个断点。调试脚本时,为什么不到这里就结束了?
DQN.py
...
...
env = PowerControl() #creates object of the class PowerControl()
..
new_state = env.step(old_state, action)
class PowerControl()
..
def step(old_state,action)
...
return new_state
`
它可能需要对我的 launch.json 文件中的设置进行一些操作。看起来像这样。
{
// Verwendet IntelliSense zum Ermitteln möglicher Attribute.
// Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen.
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Aktuelle Datei",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
预先感谢您的支持。
我不知道这是否是问题所在,但我注意到,当您定义类时,其末尾没有冒号,与定义方法时相同。此外,在类内部,方法的第一个参数通常是 self。
DQN.py
...
...
env = PowerControl() #creates object of the class PowerControl()
..
new_state = env.step(old_state, action)
class PowerControl(): # added colon
..
def step(self, old_state, action): # added colon and self parameter
...
return new_state
你的问题解决了吗?我有一个一模一样的