473,503 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Launching pdb from within a script

I asked this before, but got no response, but I KNOW YOU KNOW ;-)
A year or so ago, I was given a really useful answer to a question posed
here, which showed me how to start the debugger from withing a script.
Yes, of course I've lost the mail (and I have trawled through all my old
mail), and yes, I know I'm stupid!

I'm surprised this isn't a FAQ, BTW, as it seems such a useful facility.

So come on guys, cough it up!
Thanks
Graham Nicholls
--
#include <wit>
Jul 18 '05 #1
8 1575
Graham Nicholls wrote:
A year or so ago, I was given a really useful answer to a question posed
here, which showed me how to start the debugger from withing a script.


Are you looking for pdb.set_trace()?

Peter
Jul 18 '05 #2
Peter Otten wrote:
Graham Nicholls wrote:
A year or so ago, I was given a really useful answer to a question posed
here, which showed me how to start the debugger from withing a script.


Are you looking for pdb.set_trace()?

Peter

I think so, thanks!
Graham
--
#include <wit>
Jul 18 '05 #3
Graham Nicholls wrote:
Peter Otten wrote:
Graham Nicholls wrote:
A year or so ago, I was given a really useful answer to a question posed
here, which showed me how to start the debugger from withing a script.


Are you looking for pdb.set_trace()?

Peter

I think so, thanks!
Graham

Or maybe not.
I'm sure I was able to print the value of variables like this:

except :
pdb.set_trace()

run the program:
error message
(Pdb) d <return> (not sure why!)
(Pdb) print dentry.path
(Pdb) more debugging here

But pdb complains that there are no such variables. It may be that I had to
add some incantation around the script startup - I just can't remember (and
its frustrating!).

Thanks
Graham
--
#include <wit>
Jul 18 '05 #4
Graham Nicholls wrote:
I'm sure I was able to print the value of variables like this:

except :
pdb.set_trace() [...] But pdb complains that there are no such variables. It may be that I had
to add some incantation around the script startup - I just can't remember
(and its frustrating!).
<debugger.py>
import pdb
abc = 1
try:
print "before"
1/0
except:
pdb.set_trace()
print "after"
</debugger.py>

Now run it:

before
--Return-- /(suppressed)/python2.3/pdb.py(992)set_trace()->None -> Pdb().set_trace()
(Pdb) abc
*** NameError: name 'abc' is not defined
(Pdb) u /(suppressed)/debugger.py(7)?()

-> pdb.set_trace()
(Pdb) abc
1
(Pdb)

If the above sample session doesn't help, you could actually read the pdb
documentation - or do something new and dangerous: search google groups
for, say, Nicholls and set_trace :-)

Peter
Jul 18 '05 #5
Graham Nicholls fed this fish to the penguins on Sunday 04 January 2004
11:27 am:


But pdb complains that there are no such variables. It may be that I
had to add some incantation around the script startup - I just can't
remember (and its frustrating!).
Did you remember to import pdb at the start?

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Bestiaria Home Page: http://www.beastie.dm.net/ <
Home Page: http://www.dm.net/~wulfraed/ <


Jul 18 '05 #6
Peter Otten wrote:
Graham Nicholls wrote:
I'm sure I was able to print the value of variables like this:

except :
pdb.set_trace() [...]
But pdb complains that there are no such variables. It may be that I had
to add some incantation around the script startup - I just can't remember
(and its frustrating!).


<debugger.py>
import pdb
abc = 1
try:
print "before"
1/0
except:
pdb.set_trace()
print "after"
</debugger.py>

Now run it:

before
--Return--
/(suppressed)/python2.3/pdb.py(992)set_trace()->None

-> Pdb().set_trace()
(Pdb) abc
*** NameError: name 'abc' is not defined
(Pdb) u
/(suppressed)/debugger.py(7)?()

-> pdb.set_trace()
(Pdb) abc
1
(Pdb)

If the above sample session doesn't help, you could actually read the pdb

I have had a look, but its rather a case of you don't know what you don't
know, IYSWIM. documentation - or do something new and dangerous: search google groups
for, say, Nicholls and set_trace :-)
What a good idea!
Thanks again

PS 1 minute later and I've found the relevant posting, which indeed mentions
using set_trace().

I have in ordinary google searches of course returned ng postings, but had
never used their group searches, so thnkas on two counts.
Peter


Regards
Graham
--
#include <wit>
Jul 18 '05 #7
Peter Otten wrote:
Graham Nicholls wrote:

....
But pdb complains that there are no such variables. It may be that I had
to add some incantation around the script startup - I just can't remember
(and its frustrating!).

....
-> Pdb().set_trace()
(Pdb) abc
*** NameError: name 'abc' is not defined
(Pdb) u

This is the key line, 'n' would work as well. The reason your variables
weren't being found is that you were still inside the call to
set_trace(). You need to return from that (either by going "u"p to the
calling context, or to the "n"ext instruction, which returns to the
calling context by finishing the set_trace() call).

Enjoy,
Mike

_______________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/


Jul 18 '05 #8
"Mike C. Fletcher" wrote:

Peter Otten wrote:
Graham Nicholls wrote:

...
But pdb complains that there are no such variables. It may be that I had
to add some incantation around the script startup - I just can't remember
(and its frustrating!).

...
-> Pdb().set_trace()
(Pdb) abc
*** NameError: name 'abc' is not defined
(Pdb) u

This is the key line, 'n' would work as well. The reason your variables
weren't being found is that you were still inside the call to
set_trace(). You need to return from that (either by going "u"p to the
calling context, or to the "n"ext instruction, which returns to the
calling context by finishing the set_trace() call).


"r" (for "return") works as well....

Wow! Three obvious ways to do the same thing. ;-)

-Peter
Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
10158
by: Bob | last post by:
Hi, I'm trying to build a PHP page which launches another php script to be run in the background. The web page should return immediately, while the background script may run for 10 minutes or...
1
5821
by: David | last post by:
Hello. I've written a page for an intranet that gives the user the option of launching a Word or PowerPoint document. The code I used to force the hyperlink to launch the application rather...
8
47998
by: VA | last post by:
I have a report that is accessible by a URL. How would I go about automating the launching of this URL using, say, a batch file? I can put start iexplore.exe "http://my.url" in the .bat...
6
1287
by: LordHog | last post by:
Hello all, I was wondering what is the best method of launching an application/exectable from within the Managed VC++ environment? I have found some information which describe CreateProcess and...
1
1710
by: Water Cooler v2 | last post by:
I have a Windows Service I am writing in C# and a set of, let us say three, other executables written in C# (mostly console applications). I want that the Windows Service must do so every few...
0
1759
by: microb0x | last post by:
Is there any difference in the way an Access .mdb file is launched from directly double-clicking the file through windows explorer versus using code within another Access file to launch the...
10
3620
by: Andrew Neiderer | last post by:
I think I am asking the right newsgroup. If not maybe someone could tell me where to ask this "beginner" question. I want to click on an image (.jpg) that launches a Microsoft window (cmd.exe...
8
2266
by: =?iso-8859-1?B?QW5kcuk=?= | last post by:
I would like to find out how I can launch an independent Python program from existing one in a cross-platform way. The result I am after is that a new terminal window should open (for io...
5
1811
by: Oriane | last post by:
Hi there, I would like to run a javascript file directly from the desktop, like a VBScript file. So my post is perhaps "out of topic" in which case I apologize. The goal is to run this sort...
0
7201
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6988
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.