Hi,
I was wondering how to debug python script without adding pdb module to the script file. Say, I have a script test.py without adding "import pdb" and "pdb.set_trace()". Can I debug it in Python running in terminal by importing pdb there? How to set up breakpoints and start the debugging. I tried it this way in Python running in the terminal:

import pdb
    pdb.break test.py: 9
    pdb.run('test.py')

But there will be an error

File "<stdin>", line 1
pdb.break test.py: 9
^
SyntaxError: invalid syntax

I know I am wrong. Please tell me how to do correctly. Really appreciate your help!

Recommended Answers

All 2 Replies

The simpliest way would be using and IDE, like Idle, that has debugging built in.

Easiest way is to run it in your debugger of choice on the command-line. Since yours seems to be pdb (a pretty bad choice, really... it doesn't do very useful things like threaded debugging), try the following:

pdb script_name.py argument1 argument2 ...

It should dump you into a debugger on the first line of your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.