Baby Steps in Data Journalism

Starting from zero, this Tumblr provides tools, links and how-to information for people just beginning to explore data journalism.
Posts tagged "language"

A video-based free online course with lots of good points. It introduces JavaScript before starting on jQuery. It starts with real basics. However, it does not explain in detail — so people with no previous programming experience might feel lost. Still, it’s a very well-designed course, fast-paced, intelligent.

HT: Mark Hamilton (for the link) @gmarkham

See also: The ultimate JavaScript reference site (ad-free and up to date)

Both of these are introductory texts in computer science:

Introduction to Computing: Explorations in Language, Logic, and Machines, by David Evans, associate professor of computer science, University of Virginia (this book uses Python only in two chapters at the end)

How to Think Like a Computer Scientist, by Jeffrey Elkner, Allen B. Downey, and Chris Meyers (this book uses Python throughout; it’s online only, no PDFs)

Allen [Downey] had already written a first-year computer science textbook, How to Think Like a Computer Scientist. When I read this book, I knew immediately that I wanted to use it in my class. It was the clearest and most helpful computer science text I had seen. It emphasized the processes of thought involved in programming rather than the features of a particular language. Reading it immediately made me a better teacher.

How to Think Like a Computer Scientist was not just an excellent book, but it had been released under the GNU public license, which meant it could be used freely and modified to meet the needs of its user. Once I decided to use Python, it occurred to me that I could translate Allen’s original Java version of the book into the new language.

— Jeffrey Elkner, from the Preface, How to Think Like a Computer Scientist

Elkner is a high school math and computer science teacher in the Arlington County, Virginia, public schools.

Here’s what I learned today:

>>> def checkpage(a):
...   if a:
...     print 'ok'
... 
>>> page = 'tulip'
>>> checkpage(page)
ok
>>> page = True
>>> checkpage(page)
ok
>>> print page
True
>>> page = False
>>> checkpage(page)
>>> page = None
>>> checkpage(page)
>>> page = True
>>> checkpage(page)
ok
>>> page = ''
>>> checkpage(page)
>>> 

So, in addition to False, the value None and the empty string ( ” ) also evaluate as false. A while loop, therefore, can begin with

while True:

See: Built-in Types at python.org.

You actually know enough at this point that you could write every possible computer program using just the things that we’ve seen. This is a pretty astounding result, and I mean this in a very strong sense: Everything that could be computed mechanically by any machine can be described using a program that only used the things that we’ve seen so far. All you need is procedures [functions], simple arithmetic (with a comparison), and if statements.

— David Evans, instructor

Udacity CS101 course, Unit 2, segment 21

(And that’s what makes programming so cool !)

A good reference: Python slice notation

Interesting: All of these return your full, complete string (s):

s[:3] + s[3:]
s[:1] + s[1:]
s[:2] + s[2:]

It’s a kind of a mirror effect, asking for everything up until x — s[:x] — and then concatenating with everything after x — s[x:]. This works even if the length of s is less than 3.

Unnecessary, but it shows a little more how s[:] (slicing a string) works in Python.

If your Python version is less than 2.7, download and install version 2.7. Make sure you download the current production version.

Python 2.7 is the latest and last version of Python 2.x. There is a Python 3.x:

Python 2.x is the status quo, Python 3.x is the present and future of the language. … The downside of breaking backwards compatibility in 3.x is that a lot of that software doesn’t work on 3.x yet. [source]

Therefore, I am using 2.7 now (April 2012). I’m kind of conservative about jumping ahead to the newest version of anything.

Check for the latest information about versions on the Python home page.

Starting Python

After you have opened Terminal (or if you are not using a Mac, the equivalent Unix/Linux shell program), type this:

python

Then press Return (or Enter). You will see the word Python followed by some numbers, as shown above. The numbers tell you which version you are running.

To quit Python, press Control-d. Doing so will return you to the normal command prompt.

To quit Terminal, Command-q (just like every other Mac OS application).

The very first step is to make sure you have Python installed and running on your computer. Nathan does not tell you how to do this, but of course there are a million Web pages and blogs that can help you. There is one good place to get Python (it’s free), and that is the link in the title of this post.