Reputation: 39219
When examining a function in pdb
, I can run the r(eturn)
command, which will continue to where the function returns.
How do I print (or otherwise examine) the value which will then be return?
Upvotes: 2
Views: 579
Reputation: 13327
You can use the variable __return__
(no reference in the official doc, but you can find some details of the implementation in the source : user_return and do_retval)
def do_it():
res = 'return me this'
import pdb;
pdb.set_trace()
return res
then = do_it()
> debug_it.py(7)do_it()
-> return res
(Pdb) r
--Return--
> debug_it.py(7)do_it()->'return me this'
-> return res
(Pdb) __return__
'return me this'
(Another S.O post explains this variable)
Upvotes: 3