Python Projects - Netbeans Debugger

Im attempting to use Python in an IDE Im familar with and has a great debugger, but Im having trouble getting started with Python. Has anyone ever attempted this? There is a default piece of code when you begin a new project. Im wondering if its vital to run py scripts in debugging mode in the IDE:
if name == “main”:
Do something

So, far I cant get a new project to run in debugger mode. Any help would be appreciated. Im pretty sure once I can get to the point I can debug python scripts like I did my java apps I will be able to teach myself much more effectively. Thanks in advance.

I don’t know about your debugger, but I can explain that standard line. It’s a way to determine whether the script is imported into another module or executed on its own. In the latter case its __name__ variable will be set to __main__. You usually put code in there that shouldn’t be executed on import into another script.

So, if Im writing the script like from the book, I dont need it?

No, you shouldn’t need it.

1 Like


It’s Python’s quirky way of identifying the entry point of a programme, so you see it often when several modules are in use.

if __name__ == ‘__main__’: 

It is the equivalent of:

class X {
    public static void main (String [] argv) {

In terms of debugging Python in Netbeans, I cant help as I don’t get on well with NB. But this might…

Other people have mentioned it, but it’s kind of strange that Netbeans wouldn’t know this convention and let you specify that you’re running it “command line style”. What that line does is act as a guard so that a script can work with an import or run on the command line. I personally think that’s a dumb “feature”, but that’s how they do it. In theory Netbeans should know about this convention and let you run it … a different way? Look for how you would run it with command line options. Maybe that triggers the “main” setting.

As far as this particular problem, i found the solution. Although, I couldnt get the Netbeans 8.2 debugger to play well with the python plugin. The python scripts looked ported bc there were very basic syntactical errors that prevented the ja va debugger from executing them. Add o, I had to try a different IDE.