yoink@tumblr ~ % date

02nd August 2005

yoink@tumblr ~ % less 1122955200.txt

A Pythonic Day

Today was my day of Python. I really enjoyed this morning’s session. It was really helpful to go through and explain some guidelines and best practices for getting things done simply (or lazily if you perfer) in Python. One trick for figuring out what methods are invoked when using special methods such as add lets you trace through like so:

class chatty:
    def __init__(self, name):
        self.name = name
    def __getattr__(self, what):
        print self.name, "asked for", what
        raise AttributeError(what)

which produces stuff like:

>>> A = chatty('A')
>>> B = chatty('B')
>>> A + B
A asked for __coerce__
A asked for __add__
B asked for __coerce__
B asked for __radd__
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: unsupported operand type(s) for +: 'instance' and 'instance'
>>> print A
A asked for __str__
A asked for __repr__
<__main__.chatty instance at 0x6ea58>

Kinda neat?

There was a lot more including Duck Typing, Generators and Iterators. A lot of which I’ve come to associate with Ruby, but is available in Python 2.4 or will be soon.

The slides for this morning are available (with some other stuff) and should be updated soon to reflect any last minute changes.

yoink@tumblr ~ % notes -v $post