Pythin Startup Directions and Help

Introduction to Computational Linguistics

Programming Tools

    Python Pointers

    Start up Python and import the sys module:

    % python
    >>> from sys import * The place to start

    Python Book

    Dive into Python book site.

    This site has online copies of an excellent introduction to Python that assumes knowledge of some other programming language. In other words, it doesn't teach you how to program. But it doesn't assume any particular body of arcane programming knowledge either. It is lucid, clear, unpretentious and supplied with copious examples.

    Hint: Download to get a pdf of the book plus a directory of examples referred to in the text.

      Dive into Python: Local copy

    Especially notable: Appendix A. Further reading. A great list of elementary discussions on various topics.



    Excellent quick start discussions for beginners and more advanced programmers as well. Good place for a quick review of builtins and library methods for some data type, such as strings or lists.

      Wikibooks on Python

    A nice discussion of a lot of topics, targeting developers.

      Python Reference Manual

    1. Python Library Reference Library Ref: Exceptions Documentation.
    2. Built in function Docs
    Beginners to

    Josh Cogliati's Non-Programmers' Tutorial for Python:

      Non-programmers Tutorial for Python

    This also includes a lot of discussion targeted for beginning programmers, but goes a bit further conceptually:

      How to think like a computer scientist
    Python for

    Still in draft form, but available online:

      Ron Zacharski's Python for Linguists

    Rumor has it Mark Johnson is working on abook with a similar concept.

    Not for beginners. Not specifically targeting linguists but definitely focused on the topics of most interest to linguists:

      David Mertz's Text Processing in Python
    Donations tearfully accepted. This also a book. Info on the site. Buy the book.
    Python Apps

    Natural Language Toolkit (NLTK).

      NLTK Home page
    Style Guide  

    It doesn't really matter whether your code works or not.

    What really matters is that it fit snugly around your hips:

      Python Style Guide

    Python Knowledgebase: This has a Google-style search engine and FAQ list. And code snippets and hints....

    Python Cookbook  

    Full of useful tidbits (and code snippets!):

      Python Cookbook
    But subjects covered tend to be rather advanced.
    Doc Strings:
    Method Specific

    Functions shd be defined with __doc__ strings.

    These can be read by printing the function's doc string:

      print open.__doc__
    shows all you want to want to know about opening a file.

    You shd do this with your own functions, of course. Here's how:

    def hello_world (guy):
         Prints hello world, guy
         guy a string.
         No matter what."""
      print 'Hello world, %s.' % guy
    Now run it:
    >>> hello_world('Fred')
    Hello world, Fred
    Now read about it:
    >>> print hello_world.__doc__
    hello world(guy)
         Prints hello world, guy.
         guy a string.
         No matter what.

    Further help:

    1.'s PEP 257 Document defines doc string conventions.
    2. Python Style Guide discusses how to write a good doc string.
    3. Python Tutorial discusses conventions for spacing in doc strings (this is actually the most concise and useful).

    1. Introduction to dictionaries
    2. Python Cookbook recipe for sorting a dictionary by keys (the key-value pairs of a dictionary are UNORDERED, so if you want a list ordered by KEY, here's how)
    3. Python Knowledge Base: a lot of example code using dictionaries.
    Floating Point  

    Odds and ends about arithmetiic, of relevance to those using log probs:

    1. a href=""> Floating point special values: Discussion of infinity and the like.
    2. Reference Manual: Expressions. Syntax of basic arithmetic expressions can be fond here.
    3. Math module functions here