Python

From Center for Cognitive Neuroscience
Revision as of 00:19, 7 July 2011 by Elau (talk | contribs) (Undo revision 2718 by Raingerr (talk))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

FAQ

How do I configure my editor?

It is very important that all collaborators maintain the same editing preferences for projects when using Python. This ensures that your time will be spent programming and not debugging the often hard to pin down indentation level syntax errors that can result from having different editor settings between users.

Configuring your editor to conform to the following PEP recommendations is required and highly recommended in general

  • shiftwidth = 4
  • tabstop = 8
  • expanded tabs (replace tab with spaces)
  • wrap text after 79 columns to ensure that it does not exceed 80 columns (this is canonical programming practice in general)
  • Use unix end of line \n
  • set file encoding to UTF-8 (recommended, not required)

How do I update a matplotlib in Wingware IDE?

The answer to this question was provided by Stephan Deibel of Wingware IDE support. As of this writing, this method has only been tested in windows. For OSX, it's best to use the ipython shell with -pylab switch.

Users of matplotlib often work interactively in the Python command
line shell.  For example, two plots could be shown in succession
as follows::

 from pylab import plot,show,close
 x = range(10)
 plot(x)
 show() # This blocks until the plot window is closed manually
 y = [2, 8, 3, 9, 4]
 plot(y)
 close()

When this is done in Wing's Python Shell, the show() will not return until the
first window is closed and subsequent plots will not run interactively so
their windows will fail to update if obscured and re-displayed. This happens
because the main loop that services events for the plot windows is not being
run.

To solve this problem, try using a ``Timer`` from Python's threading module for
the ``show()`` call, as follows::
 
 from threading import Timer
 t = Timer(0, show)
 t.start()

This has been tested on Windows with numpy 1.2.1, scipy 0.7.0.b1, and a
matplotlib 0.98.5.2 installation where ``matplotlib.get_backend()`` reports
"TkAgg".  It may not work with other backends or on other OSes, although
it may be possible to devise a similar technique for other backends by
calling the GUI layer directly.

Useful Python Programs

Komodo Edit

A free and open source editor based on the award-winning Komodo IDE. You can find Komodo Edit at | ActiveState. They also offer the outstanding, but not free, Komodo IDE for a full fledged multi-lingual development environment.

Wing IDE

The | Wingware IDE is a great Python interactive development environment. It works well for general projects as well as SciPy focused projects. It features all of the things one would expect in an IDE such as code completion, project management, a debugger, built-in shell (like the matlab terminal), syntax highlighting, and much more. Please see the Wingware | Tutorials, | HowTo's, and | Reference Manual to get started. If you run into any issues and can't find the answer in the documentation, there's the | mailing lists, and | Priority Support (mostly for paying customers).

Wingware provides two versions of IDE. The | Professional, | Personal, and the | 101 versions.

The 101 version is free to everyone, but is limited in its features. The Personal is $35 dollars and the Professional weighs in at $95 (education pricing).

Free Wingware Professional

Wingware has an | amazing deal that allows one to obtain the Professional version for free with no limitations. The only requirement is that you write a useful, non-trivial program and license it under an | OSI Approved license. This, for most people, means the GPL or BSD licenses.

SciPy

| SciPy is mathematical suite for Python. It provides the same functionality as matlab, including plotting. As of yet, I have not found a function or ability present in matlab that does not have a corollary in SciPy. If you do, please let me know.