簡體   English   中英

在 Python 中的 VSCode 中調試,調試器不遵守 class 中的斷點

[英]Debugging in VSCode in Python, debugger does not respect the breakpoints in class

我是 python 的編程新手。我使用 Visual Studio Code。 我的調試器有一些問題。 當我調試腳本時,我的調試器會在腳本中的斷點處按原樣中斷。 但在我的腳本中,我還從 class 創建對象。為了調試 class 的方法(從它創建的對象),我在方法中設置了斷點。 我希望調試器跳到那里並遵守斷點,但這並沒有發生。 我有一個很長的代碼,所以我試圖縮短它。 所以在我的代碼示例中,我在 step(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" } ] }

在此先感謝您的支持。

我不知道這是否是問題所在,但我注意到當您定義 class 時末尾沒有冒號,這與您定義方法時相同。 此外,在類內部,方法的第一個參數通常是 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM