Help, Search and Substitute

Thomas Wouters thomas at
Fri Nov 3 10:35:50 CET 2000

On Fri, Nov 03, 2000 at 09:27:27AM -0000, Simon Brunning wrote:

> (I don't know why /F made 'get' a defaulted argument of the function - but
> then he's *far* cleverer that I, so there was *bound* to be something that I
> didn't understand!)

It's an optimization, as well as a way of 'extending' the function without
completely re-implementing it. It's an optimization because the references
to 'get' in the function are now local vrbls (which are relatively fast),
rather than a global lookup search, and then an attribute search on the
resulting object (which is what 'symbols_table.get' would have done.)

The extending bit isn't really necessary in this case, since the function
isn't that long, but what it allows you to do is pass in a different symbol
dict without having to change the function, and without suffering much of a
performance hit. Its advantage will come clear when you have a 1000-line
function that you want to work slightly differently. You can just write a 2
line wrapper that passes in a different 'get' method. And the 'get' method
doesn't even have to be a dictionary's get, all you need is 'a' get method
that takes a key and returns a value. It could be a SQL database, it could
be generated from the key, it could depend on other, global, variables, etc.
It's Python, the possibilities are endless ;)

Thomas Wouters <thomas at>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!

More information about the Python-list mailing list