Getting Started

The Python website http://www.python.org is an excellent resource for learning Python.  http://numpy.scipy.org/ is good for learning Numpy, the numerical package built on Python.  However, learning Damon requires little actual skill in either Python or Numpy, just a few basics.  This tutorial will focus on Damon.  The format will be "learning-by-doing" with minimal verbiage.  Don't just read.  Type each example by hand.  The fingers remember what the brain forgets.

Open IDLE
This part varies depending on the machine and the Python distribution you downloaded.  In Windows, search for Python and double-click on something that looks like IDLE (Python GUI).  This will open the Python interpreter.  On the Mac, use Spotlight to search for IDLE and open.  Make sure you're opening the right Python IDLE (the one you downloaded) -- you might have multiple versions on your system.  You should end up with this:  (My machine's a Mac and I'm using Python 2.7.2, the Enthought (EPD) distribution.)

IDLE

Python 2.7.2 |EPD 7.1-1 (64-bit)| (default, Jul  3 2011, 15:56:02) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "copyright", "credits" or "license()" for more information.

>>> 

Import Damon
Here, damon1 refers to a folder in Python's site-packages folder and core refers to a python module within the damon folder called core.py.  When importing, you don't need to include the .py extension.

Import Damon

>>> import damon1.core as dmn
>>> import blahblah

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    import blahblah
ImportError: No module named blahblah
>>> import numpy as np
>>>

Note that you get an import error if you try to import something (blahblah) that doesn't exist in the usual places where Python looks.  We have successfully imported Numpy, indicated by the lack of error message.  I have abbreviated damon1.core as dmn and numpy as np.  The abbreviation is up to you.  In the rest of the tutorial, I import damon1.core as dmn.

Create a List, a Dictionary, and an Array
Lists and Dictionaries are Python's main data containers.  Arrays are Numpy's data container.

List, Dictionary, Array

>>> import numpy as np

# Create a Python list called L.  A list can contain both strings and integers.
>>> L = [1,2,3,'a','b','c']
>>> print L
[1, 2, 3, 'a', 'b', 'c']

# Create a Python dictionary D.  Damon uses Python dictionaries extensively.  They are a quick way to look up things by name.  Dictionaries have no intrinsic order, as you can see.
>>> D = {'a':1,'b':2,'c':3}
>>> print D
{'a': 1, 'c': 3, 'b': 2}

# Create a Numpy array A.  Note that to access numpy's array object you need to precede it by 'np'.  This syntax prevents name collisions with other programs that have things called "arrays".
>>> A = np.array([1,2,3])
>>> print A
[1 2 3]

# Create another Numpy array mixing string and integers.
>>> A2 = np.array([1,2,3,'a','b','c'])
>>> print A2
['1' '2' '3' 'a' 'b' 'c']

# Numpy requires all array elements to be of the same type.  Therefore, it casts them all to the most general type that can include them all, in this case strings.  (The most general type is called "object".)  That is why the integers now have quotation marks around them.  They are no longer numbers.

# Elements of a list are accessed through "slice" syntax.  The 0 in square brackets means get the zero'th element in L.  (Python always counts from 0.)
>>> L[0]
1
>>> L[1]
2
>>> L[3]
'a'

# Dictionary elements are accessed by name rather than position.
>>> D['a']
1
>>> D['c']
3

# Array elements, like lists, are accessed with slice notation.
>>> A[0]
1
>>> A[2]
3
>>> A2[0]
'1'
>>> A2[5]
'c'
>>> 

Damon uses these data containers a lot, especially arrays.  Play around with them.  There is another Python container, "tuples", which are like lists but can't be changed.  They are signified by parentheses (...).  Python functions and methods contain their arguments (parameters) in tuples.