Main Content

Python in an afternoon - a lecture for experienced programmers

Archive - Originally posted on "The Horse's Mouth" - 2008-06-01 10:46:16 - Graham Ellis

Last Friday afternoon I was set a challenge - to present Python in three hours to a group of 20 very experience programmers who, however, knew nothing about this particular language.

The session was in Central London - my directions started off with "Get off the Tube at Oxford Circus", so Londoners will know just how central I mean - so I took First Great Western's Penzance express from Westbury into Paddington. It's great to have power at your seat for laptops these days, though the new airline style seats in second class (oops - standard class!) are a bit tight for working on, and the computer jump horribly when the guy in the seat ahead gets up or flops down.


"Python in a nutshell" - no - that's NOT what I entitled the talk, but I went through the various features that will be mainstream for this group (I had had their applications described to me ahead of time), and I concluded with an example which - in less that 1500 bytes including comments - shows a short and simple use of many of the features os the language.

• Variables and Loops
• Comments
• Lists, Tuples, Dictionary
• Functions, Modules, Object use
• Variable scope
• Documentation Strings
• Regular strings, triple quoted strings and raw strings
• Regular Expressions
• Formatted String Outputs
• File Statuses and File Handling.
• Prompting and reading from STDIN
• Exception handling and error exiting

In some horror, I notice that my example doesn't have a single if statement in it but - hey - I don't think I did too badly in getting so much in to a practical piece of code ... [source code here]

grahamellis$ python lfan
This is a program which reads a web server access log
file and counts the number of times each browser has
visited, outputting the results sorted by the number
of accesses
 
Press return to proceed
Processing 13973 kbytes
     1 pd95215e4.dip.t-dialin.net
     1 cache-ntc-ab01.proxy.aol.com
     1 host-66-81-36-237.rev.o1.com
     1 cache-mtc-al03.proxy.aol.com
[snip]
   306 sjcd-webcache-3.cisco.com
   309 193.116.20.220
   327 crawler10.googlebot.com
   348 crawler14.googlebot.com
   407 ip68-110-77-129.ph.ph.cox.net
   970 82-33-81-221.cable.ubr03.trow.blueyonder.co.uk
Total of 67756 visits from 5048 hosts
grahamellis$


How did the afternoon go? Well - I enjoyed it and my whole audience remained, right through to a quarter past five when I finished. A handful of excellent questions afterwards. And a comment from my contact there, who isn't technical himself and had meetings during the afternoon - "Graham - I came back at about five and looked in through the window. The degree of concentration after three hours from everyone was quite remarkable".