PPL30 Day 15: Python

Python! This ought to be fun. It’s really not fair, though. How large is the gap between Python and Ruby? Crossing the street is more endeavoring! Well, perhaps, but I want to know it. That’s the important part. Plus, people could call me a Pythonista, which, though sometimes used derogatorily, really rolls off the tongue. Wouldn’t you agree? It sounds expensive, doesn’t it? Bloody royalty, those Pythonistas.

Sir Hiss

This is part of the Peer Pressure Learning 30 series. To learn more about what in the hell that means, see the intro to the series, A Good Time To Learn.

Installation

Of course:

brew install python

Resources

Dive Into Python

As far as I can tell, 9 of 10 Pythonistas recommend starting with Dive Into Python. Those are the kind of numbers I use to choose my toothpaste. It seems they would be more than adequate for choosing a resource for learning a programming language.

The book is recommended not without reason: it’s good! It’s quite readable, but gets you going with something that at least seems more interesting than even our esteemed FizzBuzz work starting with chapter 2. I stuck with it for the duration of my time.

Python Challenge

Python Challenge is a riddle site whose riddles are intended to be solved using Python. Honestly, it would probably be a good way to learn some of the common methods and abilities of just about any language. I went through the first few, and then grew a bit weary of it all, but it might be worth your attention. Just try not to turn your attention towards it at 1AM. I’ve found it to be less effective at that hour. … Perhaps that’s an issue on my end, I don’t know.

What I Think I Now Know

Whitespace! It’s so scary!

No, it’s not. Actually, I sort of like it. It can be elegant and readable. Also, it’s really nothing to worry or gripe about. (People who’ve not used Python: significat whitespace was the first thing that ran through your mind when you say ‘Python’ atop today’s article, wasn’t it? C’mon. You can be honest with me. You permanently associate Python and significant whitespace.)

It was interesting for me to see that Python has list comprehensions that look much like those I’ve seen earlier this month in Haskell and Erlang.

It’s hard for me to elaborate on Python. Why? Well, it’s not so different from Ruby, is it? Many of the same principles and paradigms are at work here. High-level. Garbage collection. Both are dynamic, strong typed. Of course, both have an interactive console. There’s good introspection. Everything is an object in Python (though there are a lot of built-in methods that are not called on an object, but instead take the object as a parameter (e.g. type(5) instead of 5.class), which threw me off.) My FizzBuzzz could be very easily translated to Ruby by a Rubyist that has never seen Python code:

<% coderay(:lang => :python, :line_numbers => :inline) do #_ -%> def fizzbuzz(num): result = ‘’ if num % 3 == 0: result += ‘Fizz’ elif num % 5 == 0: result += ‘Buzz’ else: result = str(num) print result

if name == “main”: [fizzbuzz(elem) for elem in range(100)] <% end -%>

I have a few concerns that are holding me back here: I think in Ruby. I’d be comparing Python to Ruby constantly, were I to speak freely. Chances are it would only invite the holy war on to my patio, and, really, patio holy wars are good for no one (except the holy war patio defense contractors). It wouldn’t really be fair for me to compare the two, considering writing FizzBuzz in Python hardly makes me qualified to judge Python. Many, if not all, differences seem so minor as to make comparison seem trivial and dull, anyway.

Besides, I’m going to be diving into Django (someone’s already written that, – “Diving Into Django” – haven’t they?), soon. I’ll get the opportunity get to know Python a bit better at that point. In fact? Tomorrow. Tomorrow I’ll do Django. I’m doing it. It is DONE.

boondock saints