Optimum python IDE for debugging?

1355
16
02-28-2013 02:25 AM
JT2
by
New Contributor II
What is ESRI's 'official' stance for which Python environment to debug in? Pythonwin seems to be advocated, but I've noticed there are others such as pyscripter. Which one offers the best debugging environment? And the best intellisense / autocompletion?

I see there is some guidance here http://blogs.esri.com/esri/arcgis/2010/09/14/review-of-ides-for-python/ but I really think that ESRI needs to take a more proactive stance here, because Python adoption is surely premised on the quality of the tools that we can use to debug, which at the moment is nowhere near as easy as say VBA or Visual Studio.
Tags (2)
0 Kudos
16 Replies
BradPosthumus
Occasional Contributor II
Thanks for your reply. Well I get this behaviour consistently, and it can make it VERY difficult to debug because the Python window (for me, at least) ignores blank lines.

Here's a sample script:

for i in range(4):
   print i

print "complete" x


As you can see, there are four lines. It's nice to have blank lines because it helps to organise the code.

Naturally there is a deliberate error, and this is what the Python window says:

>>> for i in range(4):
...    print i
... print "complete" x
... 
Parsing error <type 'exceptions.SyntaxError'>: invalid syntax (line 3)


It says the error is on line 3, when we all know it's on line 4. This is because the Python window ignores blank lines, either when you paste them in, or when you right click and choose Load to open a script.

This is the behaviour that troubles me because all correspondence between errors and the original script is lost, and that is a bad thing because it's very hard to count lines in your original script editor. Any solutions?


Which IDE are you using, if any? It doesn't look like you're actually running your script, but instead you're retyping your code directly into the Python prompt (your second code snippet). In this case it's giving you a legitimate error message - the third line of the code block you typed into the Python prompt has the syntax error. If you add the blank line to your code block, then it tells you the syntax error is on the fourth line (using Python interactive window directly in ArcGIS 10.1):
>>> for i in range(4):
...    print i
... 
... print "complete" x
... 
Parsing error SyntaxError: invalid syntax (line 4)


Your first code snippet presumably is your actual script that you need to run. If you're using an IDE like IDLE or PythonWin, the IDE won't allow you to run it due to the syntax error. Instead the IDE will place the cursor next to the location of the syntax error in the script. If you're not using an IDE and you try running the script using the Windows command line (cmd), it will tell you the syntax error is on line 4. There shouldn't be any case where Python is ignoring blank lines when reporting line numbers in error messages.
0 Kudos
JT2
by
New Contributor II
Thanks. I should clarify that I'm running my code within the Python window in ArcGIS (as in Geoprocessing -> Python). This is how I always prototype scripts. I find it superior to using an IDE for testing scripts because a) it's easier to reference objects using their names rather than providing full paths, and b) it's useful to see results appear in the map window. You don't get that kind of visual feedback using an IDE.

So, given the advantages of using the Python window to execute code, even if that means editing and saving that as a script in another application, how can I get it to stop ignoring blank lines when I paste or load a script? Thanks
0 Kudos
BradPosthumus
Occasional Contributor II
I can't seem to reproduce this problem (using 10.1). Here's my workflow:

1. Create a script in notepad or whatever. Insert blank lines somewhere in the script. It can be saved as a Windows file or a UNIX file, it doesn't matter.
2. Load the script in the Python window within ArcMap.
3. Blank lines appear in the Python window. Error messages cite the proper line number.

Same with typing in lines manually. It includes whatever blank lines I enter (using shift-Enter to add blank lines) in the line count. I tried it in 10.0 SP5 as well but I noticed it doesn't return any line numbers in the error message.

Are you using the same type of workflow, with the exception of #3 where the blank lines don't appear in your case?
0 Kudos
JT2
by
New Contributor II
Thanks Brad. This is really strange. Attached is my script py (also pasted below, as before), it has a blank line at line 3.

I copy it from notepad and paste into the Python window. As soon as I paste, the blank lines are gone, see picture (attached)

[ATTACH=CONFIG]22395[/ATTACH]

The same behaviour occurs when I right click in the Python window to load the py file. Edit -> Past Special... -> Unicode text also does nothing. I'm on 10.0 SP2.

Why does this happen for me and my colleagues? Thanks

for i in range(4):
   print i

print "complete" x
0 Kudos
BradPosthumus
Occasional Contributor II
I tested your script in 10.1 and 10.0 SP5 and the blank lines appear for me when both pasting in the code and loading it in. Maybe installing SP5 would fix the problem?

As an aside, I noticed in 10.0 the error messages only contain line numbers for syntax errors and not for runtime errors. In 10.1 the line numbers show up in all error messages.
0 Kudos
JT2
by
New Contributor II
That's interesting, I wonder if this appears in a list of known issues. Either way, thanks for investigating, Brad.
0 Kudos
SendhilKolandaivel
New Contributor
I have heard good things about Komodo IDE by ActiveState:

http://www.activestate.com/komodo-ide

It is about $300, and can has code intelligence for a variety of languages including Python, PHP, Perl, Ruby, Tcl, HTML, JavaScript, CSS, XML, XSLT, Node.js, etc.

Sendhil
0 Kudos