[sac-forum] Paul's Programming

  • From: Paul Dickson <dickson@xxxxxxxxxxxxxxxxx>
  • To: SAC Forum <sac-forum@xxxxxxxxxxxxx>
  • Date: Sat, 26 Jun 2004 08:04:49 -0700

I originally thought about doing this for the club's newsletter, but
technical problems with it's production would be great (eg examples use a
lot of vertical, but little horizontal space) and the articles would only
appear slowly.  So I'm posting them here

        -Paul
-----


It's been a long time since there's been a universal programming language
the likes of BASIC.  At one point, just about every personal computer came
with it, usually built directly into the ROM in lieu of a operating
system.  But now I think I've found another language that's available for
every machine, be it Windows, Mac, Linux, and mainframes; and no, it's not
Java.

I'm talking about a language called Python (named in honor of Monty
Python's Flying Circus).  It is both a compiled language like Java, but it
also contains an interpreter that can be used very similarly to the way
BASIC was on those old PCs.  The interpreter can be used simply as an
advanced calculator, or a test bed for developing programs.

Unless you are running a distribution of Linux, you will have to download
this programming language.  You'll find it on the web at:

        http://www.python.org/download/

I'll leave the installation up to you, but please post any problems you
might have to this mailing list, SAC-Forum.  Either I, or someone else can
then help you.

On the above site, there are links to documentation and tutorials, so this
series of articles won't be a in-depth look at the language, but more a
quick look with examples.

You can get to the interpreter in at least two ways: open a Command Prompt
session and typing python, or launching idle.  From my terminal window on
Linux, when I type "python", I get:

    Python 2.3.3 (#1, May  7 2004, 10:31:40)
    [GCC 3.3.3 20040412 (Red Hat Linux 3.3.3-7)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>>

You should get something similar.  To exit, press-and-hold the control key
and press Z.  On Windows, this signals an End-of-File, so the program
stops reading input and exits.  On Linux, the same function is Ctrl-D.

The >>> is a prompt.  The cursor is waiting there for my input.

    >>> 3+4*5
    23
    >>> a=3; b=6
    >>> a+b
    9
    >>> c=a*b
    >>> print c
    18
    >>> a="Testing"
    >>> a.lower()
    'testing'
    >>> a[:4]
    'Test'
    >>> print a[:4]
    Test
    >>>

This briefly shows some math, assigning variables, text strings, and
slices of strings.

Next time I'll touch on lists and dictionaries, which are very flexible
versions of arrays and structures/records, respectively.  Eventually I'll
show how to use Python to access the SAC databases.

If you want a lot more info about this language, I recommend the book
"Learning Python" by Mark Lutz and David Ascher.  The second edition is
only 6 months old, so it's very up-to-date.

        -Paul

Other related posts: