I was playing with the following code to check the behavior of pdb in vscode.
Bring the breakpoint to the print ("start") on the second line from the bottom and start
I will proceed with step into .
After a=100, when the cursor comes to print(a),
In GUI operation, if a=1000, the number will be updated, but it will be returned to 100 immediately. (Not updated?)
You cannot update the global variable from DEBUG CONSOLE in the first place.
In pdb, is there a way to enter or update global variables using DEBUG CONSOLE, etc. within a function?
defmain():
global a
a = 100
print(a)
func1()
def func1():
b = 200
print(b)
func2()
def func2():
c=300
print(c)
func3()
def func3():
d = 400
print(d)
print ("start")
main()
When you enter print
in main()
, it is not reflected as globala;a=1000
from the debug console, or simply by modifying it to a:100 <1000
in the VARIABLES frame, it is not reflected in the output of the print
function.
In the CALL STACK frame, you must change it to the stack frame that you want to be interested in (what level you are at if you are in a hierarchy of functions, or the global variable is the best), and then enter the above.
© 2024 OneMinuteCode. All rights reserved.