Python is such a popular language that most "programmers' text editors" have at least rudimentary support, including syntax highlighting. But there are several editors that have especially good support. I've tested the following editors, presented in alphabetical order, as most are fine choices:
Emacs is not really a single text editor; it's more a family of text editors that is almost 40 years old, starting with TECO EMACS, which was a set of text-editing macros implemented by Richard Stallman using the TECO editor/programming language, and continuing to be developed today with GNU Emacs, also created by Stallman. There have been other Emacsen, including Gosling Emacs and most prominently XEmacs, but they have all been mostly supplanted by GNU Emacs. It runs on Windows. Mac OS X, Linux, BSD, Haiku, Minix, Android — more or less everywhere.
Emacs' claim to fame is its extensibility, which has allowed its users to create editing modes for almost everything, really. Emacs has modes for every major programming language and most minor ones; it can serve as a newsreader, an email client, a web browser, terminal emulator, image viewer, and blogging client; it has a package manager, Bible-study tools, a web server — you begin to see the point. Emacs is huge for a text editor, but it has been called an operating system for a reason.
Python has not been neglected by Emacs extenders;
python-mode is included in the base distribution, which allows editing of Python code with syntax highlighting; automatic indentation; descriptions of keywords, modules, classes, and more on the fly; snippet insertion; an interactive Python REPL in a split window with the ability to do partial recompilation; code folding; and more. With the addition of
anything-ipython, available using the package manager, powerful syntax completion is easily available, including any modules that you import. There are also several packages for integrating unit testing, virtualenv, pylint, on-the-fly error indication, and more. With the
pymacs package, you can even use Python to extend Emacs itself, though I don't recommend it if you think your extensions might ever be useful to anyone else.
The downside of Emacs is its insane learning curve. Its model of text is different than anything you're used to, its keyboard shortcuts are nothing like today's de facto standard, and its look and feel is straight out of 1985. It does, however, have a tutorial built in — read the opening screen carefully to see how to open it — and there's much more documentation accessible on the fly, once you've learned to use it. And once you've learned to use it, you can use it to do
In short, to be effective, Emacs must be a way of life — but it's a good life if you stick to it. This article was written with Emacs; everything I finish is written using Emacs.
Geany is a cross-platform programmers' text editor that supplies the very most basic features of an IDE. It has Python syntax highlighting; rough auto-indentation, though no auto-deindentation after
break statements; reasonable code navigation; code folding; stack trace parsing to locate errors; and, with an extra plugin, some decent snippets — and that's about it.
Geany does what it does well, but what it can't do well, it doesn't do at all. Its main advantage is that it satisfies the minimum requirements for a serious Python programmer's editor while having a gentle learning curve. If you don't have an editor to which you're attached, and you don't want to put the time into learning Emacs or Vim, Geany is not a bad choice.
Komodo Edit is an editor/light IDE comprised of the free subset of ActiveState's Komodo IDE. The good points:
- Auto-indentation works well
- Project and code navigation is effective
- Code folding works well
- Auto-completion works well within a project
- Snippets are excellent and well-handled
There are some serious drawbacks, however:
- Auto-completion does not work for non-standard modules
- There is no Python console
- There is no debugging or even built-in support for running your scripts
- Project handling is low-functioning and opaque
The functionality available does not justify the IDE-like interface overhead.
Notepad++ is at base a decent text editor, but it's barely a programmer's editor, at least for Python. It has acceptable syntax highlighting, but that's about all it has to offer. It has word- and function-level auto-completion based on the current file, which is almost no help; nominal auto-indentation which does not function at all for Python; and that's all, frankly. Its only recommendations are that it's easy to learn and better than its namesake.
Unless you're tied to Notepad++ for some reason, Geany or one of the other editors recommended here is probably a better choice.
SciTE was originally a demonstration application for the
Scintilla source-code editing component, but it got out of hand and turned into a real text editor scriptable in Lua. Despite its history, it's actually quite nice, and does most of the text-editing work Geany above does; what it lacks is the project- and file-navigation functionality. It is capable of very rough auto-completion using token files, if that's useful to you; it isn't to me.
SciTE has two advantages: it's light and fast, and it's easy to learn. Like Geany, it is a minimum editor for serious Python programmers, and if that's all you want, it might be a good choice.
SPE, which is about midway between a dedicated Python text editor and a Python IDE, looks very promising but ultimately fails to deliver an acceptable editing experience. The basic editor is effective enough and immediately usable, and it provides a number of good tools, including a well-integrated Python console, an effective search panel, and file browser.
The website for SPE promises syntax highlighting, auto-completion, auto-indentation, syntax checking, wxPython GUI designer, and integrated debugger, but some features are more successful than others. I tested the latest stable release, 0.8.4.h, and while syntax highlighting, auto-indentation, syntax checking, and the GUI designer all functioned acceptably, auto-completion was unusably bad; outside of the most common parts of the standard library, suggestions seemed to be simply pulled from a list of every token in the file. The integrated debugger completely failed to work; the editor crashed hard every time I tried to invoke it.
While SPE looks like a good start at a Python editor or proto-IDE, the last stable release was in 2008, so it looks decreasingly likely that its initial promise will come to fruition.
Sublime Text is a seriously nice programmers' editor, and it has the advantage of being attractive — like, Mac-level pretty. It has a remarkable selection of powerful features, including multiple cursors (allowing the same edit to be made in multiple places at once), a flexible "goto anything" interface, a command palette that allows easy keyboard-based access to all of Sublime Text's functionality, split-screen editing, distraction-free mode, and two kinds of customization: a relatively simple one using JSON, and a more advanced plugin API using Python.
All of these capabilities are attractive, and they are almost enough to recommend the editor by themselves. However, there are a number of flaws. Auto-indentation exists, but does not handle much beyond adding a level of indentation after each colon. Auto-completion is available via the SublimeCodeIntel or SublimeRope plugins, but is not very advanced in either case. The great part is that since the editor is so extensible, you can fix these problems if you wish.
I can't fully recommend Sublime Text, based on the poor performance of the plugins in my test, but the editor is so excellent that if you're not a frequent user of auto-completion, you might consider it. I could see using this as my primary editor for Python if I weren't otherwise attached.
Vi is the anti-Emacs, and also an excellent text editor. Created in 1976, it is old in software terms, almost as old as Emacs. It is light, fast, and is almost always installed by default in Linux and other Unixes. Vim — vi improved — is the most common implementation of vi today, though there are others. Vim or elvis, another clone, is available on Windows, Mac OS X, BSDs, Minix, Haiku, and most other operating systems. Vim has extensions to allow it to edit almost any programming language, no matter how obscure.
Vim has syntax highlighting, code folding, and automatic indentation built in, and with some modeline comments in each source file or a few additions to its settings file,
.vimrc, it can ensure that you don't mix spaces and tabs. With
jedi-vim it can do auto-completion, including non-system modules, and there are a host of modules that let it do almost anything with Python code that is listed for Emacs above. Vim is also extensible using a built-in scripting language, VimScript, though in general Vim users have refrained from the exuberant extension characteristic of Emacs. (I'm no vim expert, but John Anderson is; for advanced tips on setting up vi for Python, see his article on
Turning Vim into a modern Python IDE).
Vim, like Emacs, has a learning curve like a smack in the face — maybe even steeper than Emacs, since it is a modal editor, in which different categories of operations, such as navigation and editing, are active at different times. Vim has excellent help built in, accessed by entering
:help; it includes reference guides and a tutorial.
Vim, in fine, is another text-editor-as-lifestyle. Most committed vim users use vim for almost all their editing.
There are a lot of decent editors for Python, but a few stand out: there's the lifestyle editors, Emacs and Vim, both of which are powerful but have vicious learning curves. There's SciTE and Geany, which, like any number of similar editors, are a good basic fit for someone who wants to get into Python programming without putting a lot of effort into their editor. And finally, there's Sublime Text, which, while flawed, has a number of unique features and looks poised to become for this generation what Emacs and Vim have been to previous ones: their own editor for everything.this interactive course on the basics of Lists, Functions, Packages and NumPy in Python.