Skip to content

Python

NB: Links to external websites appear in a new Window or Tab, depending on your browser settings.

Running Python from the (Unix*) terminal window

Open a terminal window. At the prompt ($) type
$ python
>>>

">>>" is the Python prompt. Try a little addition:
>>> print (11+12)
33
>>>

to exit python back to the shell, type:
>>> exit()

If Python is in a "hung" state, i.e. there is no python prompt (>>>) or it doesn't respond to the >>> exit()command, use ^d
(^d = "control-d" :  hold the control key down and type the letter d)

[On OSX machines, the Unix* operating system is accessed via the Terminal program which  can be found in the Applications/Utilities folder.] If your machine doesn't have a python installed on it or you'd like to use a more up-to-date version, see Which Python?, below.

Learning Python 

  • Dive Into Python  A little more in-depth, topic-oriented. Contains references to other related work, cookbooks etc.         
  • Python Cheat Sheets
  • CS for All A general reference for learning the basics of computer science, using python.

Project Development Tools

  • A Python Interactive Development Environment (IDE). For the sake of consistency and flexibility, we use
      •  PyCharm Community Edition. (Links to the downloadable for the Community Edition)
      • Spyder-IDE is nice and comes with an Ipython (interactive python) interface. I get confused by the detachable windows and find I use the return to default window setting (menu: View/Reset window layout) far too often 🙂 . I think it still comes with the Condo Python distribution.
      • Textwrangler for quick hacks. Now incorporated in BBEdit. Beware of OS version restrictions.
      • Vi / ViM for even quicker hacks. VIM is included in most UNIX OS including Apples OS-X.
  • vinta/awesome-pythonA curated list of awesome Python frameworks, libraries, software and resources. If you know what you're looking for, go to the awesome github repository.
  • Python packages for audio.
  • Supriya. A Python 3 API for Supercollider (watch this new development) 
  •   (sub-component of Python for Engineers, below)
  • Python for engineers Contains sub-component, Audio and DSP in Python

Which Python?

 Anaconda Python (overview) is my preference for scientific and sonification design work, because it:

  • Is available on the major hardware/OS platforms.
  • Is easy to install and maintain. I'm using the two latest versions of Python: 2.7 and 3.5.
  • Can be installed independent of any OS system python, including onto an external device.
  • The Distribution version is free, with an Enterprise version available. 
  • The Csound Python API works with it, using ctcsound.py which comes with the Csound Installers
  • Contains over 1000+ packages, including the a numerical array processor (NumPy) and a mathematical plotting library (matplotlib) well as many data-oriented tools for various platforms. See Package List
  • Uses Conda for Package maintenance, dependency and environment management. Everything just works!

Other Python tools of interest

  • A comprehensive set of Excel tools, including  PyXLL, a Python Excel add-in,  and an overview of a number of tools available through Anaconda python: openpyxl, pandas xlsxwriter, xlwings, xlrd, xlwt

 

See also: Sonification with Python Workshop