I recently had occasion to play with some Python at work (a small script to do some configurations, and I didn’t want to do them in bash), so I took the time to get all of this set up. It’s all so very easy and not worth writing about. However I thought that the interactive debugger (which is awesome, btw) has a small issue that needs resolving. Mean-time, here’s a work-around.
The issue is: the debugger (which runs in Jython) starts in the NetBeans 6.5 install directory, but the normal run-time is in the project’s source directory. Normally this is not a problem, unless you’re writing a script to pick up files from the current directory. If you just dump your data file in the project’s source directory, then it’ll work when you run it (with the F6 key), but not when you debug it (Ctrl-F5).
The work-around: The debugger is interactive and includes a Jython shell which is integrated into your debugging context (so cool)! Upon starting the debugger, your can just issue these commands:
>>> import os, sys >>> os.chdir(os.path.dirname(sys.argv))
This will set the CWD for the current debug session to the directory where your script file is. That’s where the CWD is set when you run scripts normally with the F6 key.
The solution: I’ve sent an enhancement request to the Python-IDE team in NetBeans’ issue tracker. I’m not sure where the CWD should be set in the general case, but probably it should be in <project-base>/src to be consistent with the normal runtime.