Contents
Introduction
A less invasive way
Decorators
Improving echo
Wider application
Work in progress
Source Code
Credits
@ end
Introduction
Let’s suppose you want to trace calls to a function. That is, every time the function gets called, you want to print out its name and the values of any arguments passed by the caller. To provide a concrete example, here’s a function which calculates the dot product of two vectors.
def dot(v, w):
"""Calculate the dot product of two vectors.
Example:
>>> dot((1, 2, 3), (3, 2, 1))
10
"""
return sum(vv * ww for vv, ww in zip(v, w))
To trace calls to the function you could just edit it and insert a print statement.
def dot(v, w):
print "dot(v=%r, w=%r)" % (v, w...
Content suppressed by ://URLFAN, for full article visit source
Sugar PieFrom: feeds.wordaligned.org
Post Date: 2008-03-06 00:00:00
Question: in the code snippet bleow, what does the result stream, rs , approximate?
from itertools import count, ifilter, izip
from random import random as xy
from math import hypot
pt = lambda: (xy(), xy())
on = ifilter(lambda n: hypot(*pt()) < 1., count(1))
rs = (4. * j / i for i, j in izip(on, count(1)))
The code isn’t wilfully obscure but I’ll admit it’s...
more Drawing ChessboardsFrom: feeds.wordaligned.org
Post Date: 2008-03-18 00:00:00
Contents
The Python Imaging Library
ImageMagick
Google Chart API
ASCII Text
Unicode Block Elements
And more
Why?
Teaser
Thanks
I wanted a picture of a chessboard. Rather than boot up some drawing software and cut and paste black and white squares I decided to write a program to create the picture.
If you’d like to know why anyone would ever create work for themselves in thi...
more Ima Lumberjack, (s)he’s OKFrom: feeds.wordaligned.org
Post Date: 2008-03-24 00:00:00
Introducing the team
Ima, the new recruit, paired with Alyssa, our most experienced programmer. The two of them worked on the user interface. Noah and Seymour looked after the persistent storage layer. Once Seymour got Noah into unit testing — well, you just couldn’t stop them. Cy managed the build, installation, porting, tools, and generally helped sweep up any regressions. What a star! That left me, Lem and Eva free to work on the core of the product. Ben led the team, but you ...
more