Which editor should I use for python programming?


There are a lot of ways for editing and running python code (also called a  program or a "script"); to get you started here are a couple of free editors and IDE, all are open source or part of Windows or Mac OS.

Editors
At the minimum you need a general-purpose text editor to create/modify a textfile (say "helloWorld.py") and a command line shell (terminal) in which to run the python interpreter with your script as argument  (here: python helloWorld.py). Shells typically have command line recall (arrow up, arrow down) and file name completion (Tab key) to cut down on typing. (More on the python interpreter here)
  • Windows
    • Notepad (minimal functionality), Notepad++ (open source, lot more functions not python specific) 
    • Shell/terminal: start Python (command line) (in Program Files\PythonX.X) or run cmd.exe (Run... type in cmd), 
  • Mac (more on Python on the Mac)
    • textedit.app (make sure to initially save the program as plain text, cmd-shift-t)
    • TextWrangler (freeware, looks nice, has python syntax coloring, haven't used it myself yet)
    • Shell/terminal: terminal.app (/Applications/Utilities folder or spotlight it)

Python IDEs (Integrated Development Environment)
IDEs offer more specific functionality for programmers than text editors and allows to to run python scripts "inside" (usually including an interactive python shell version). The standard IDE for python is called Idle. See Chapter 3 in the textbook (How you run programs) or here. Although it's somewhat basic, it's usually installed as part of the Python on Windows, Mac and Linux.Check out the Configuration options  and keyboard shortcuts (also under Edit). A couple of notes:
  • Interactive Python shell
    • Previous/next line in your command "history": Alt-p / Alt-n on Windows (Mac: Control instead of Alt), rolls over
    • I usually just roll backwards (or forwards) one line at a time but if type a couple of letters first and then press Alt-p/Alt-n and you will only get commands starting with these letters. So if you earlier evaluated three lines starting with print, typing pri and hitting Alt-p will bring back each of these earlier lines
  • More on completions:
    • Alt-/ (slash) will expand keywords, including user defined functions (same file or shell)
    • Control-Spacebar will let you chose from a list, up/down arrow to move, Return to select
  • File - New opens a new file editor, you need to manually append .py when saving a file  
  • Formatting code (Editor):
    • Indent/Un-indent mouse selected lines  with Control-[ and Control-] (Mac)
    • Comment/Un-comment: Alt-3 / Alt-4
  • Run script in Editor: Hit F5 (edit window has to be active not the shell, you can turn off Save reminder with Windows-Configuration-General-No Prompt)
  • Got errors? To jump to the error's line: right-click on the Trackback block - Goto file/line
  • (Something I'd like to know myself: Running a script with arguments from within Idle)
  • Downside: visual debugger is clunky, have not tried the pdb command line debugger
Other python IDEs:
  • PythonWin (pywin32) is another pretty basic (Windows only) Python IDE that includes minimal GUI debugger.  
  • Wing IDE 101: free, basic edition of the Wing commercial Python IDE, Windows, Mac (via X11) and Linux. For me it offers just enough functionality (especially the debugger) without getting too confusing :) Version 4 just came out. Download here or scroll down to Wing IDE 101 on the downloads page
  • pyscripter : open source, Windows only (?)
I have used Wing 101 for a bit now, it has a good mix of simplicity and features, I would imagine it's good enough for small projects (bonus points for vim key bindings ;). Pywin seems pretty decent but I haven't used it a lot. I have only played a bit with  pyscripter, it seems to have more features and complexity than Wing 101 (like a project definition, watches and todo list).

Links to other IDE's submitted by students (as I didn't originally enable comments and apparently can't turn them on for older posts:

Aptana (http://www.aptana.org/studio) - submitted by Jason (seems to be mostly a web dev thing?)

Search This Blog