[portland] Using log() programmatically

Adam Lowry adam at therobots.org
Fri Sep 28 20:57:34 CEST 2007


On Sep 28, 2007, at 11:47 AM, Robin Dunn wrote:
> Instead of making the dictionary keys a value, you can make it be a
> function, something like this:
>
> def do_times1(val):
> 	return val
>
<snip>

I was just about to suggest something similar. I would probably use  
anonymous functions here - same effect, a little tighter code:

self.scaleDict = {
     'x 1': lambda x: x,
     'x 10': lambda x: x * 10,
     ...
     'x log 10': lambda x: math.log(x, 10),
     'x log 2': lambda x: math.log(x, 2),
     'x log e': lambda x: math.log(x),
}

self.scaleDict[key](x)

Adam


More information about the Portland mailing list