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 a recap if you are just joining me: I started this blog on April 8, 2012, because I am reading Nathan’s book about how to make data graphics. I think data graphics are very important for journalism, now and in the future.
So when I reached the first exercise in the book (around page 31), I decided to open up Python, a programming language, on my MacBook and play along.
I had an older version of Python, so I installed a new one.
Then I installed something called ActiveTcl, which Nathan does not mention.
I managed to complete the exercise, in which one scrapes data from 365 separate Web pages (hooray!) Then I made a graphic from my data, using MS Excel.
I have indulged in a few distractions along the way:
That’s everything up to now.
After showing us the basics of scraping a Web page, Nathan provides a script so that we can scrape a year’s worth of data from 365 separate Web pages (nice!).
But don’t think you have to type the script with your own little fingers. Like all good code book authors, Nathan has provided the code from the book as a download:
> Downloads page for Visualize This
NOTE that you will need to edit the second line of the script (use a plain-text editor) because of the error on page 32 (see explanation of the error).
> See all posts in this blog about this book
p. 31 DOES NOT WORK:
p. 32 DOES NOT WORK:
from BeautifulSoup import BeautifulSoup
from bs4 import BeautifulSoup
p. 33 FURTHER EXPLANATION:
After you have found that the value you want (maximum temperature, which is 26°F) is enclosed by span tags with class=”nobr”, you need to know how to find out WHICH class=”nobr” you will be scraping. Nathan tells you it’s nobrs … but how can you find that number (5) for yourself? (I will assume you know how arrays work.)
Memo to self: Journalism students are not likely to understand what an array is and how it works.
*You may see the temperatures in °C, depending on which country you’re in.
I wanted to do some of the things recommended in Nathan Yau’s excellent book Visualize This: The FlowingData Guide to Design, Visualization, and Statistics (2011: Wiley). So after I had about 120 lines of notes in a text editing program, I thought: “Hey, with so many links and stuff, I should turn this into a Tumblr!” So here it is.
Check out Nathan’s popular blog, FlowingData.