A critic of Guido's blog on Python's lambda
Serge Orlov
Serge.Orlov at gmail.com
Sun May 7 02:17:34 EDT 2006
Ken Tilton wrote:
> It is vastly more disappointing that an alleged tech genius would sniff
> at the chance to take undeserved credit for PyCells, something probably
> better than a similar project on which Adobe (your superiors at
> software, right?) has bet the ranch. This is the Grail, dude, Brooks's
> long lost Silver Bullet. And you want to pass?????
>
> C'mon, Alex, I just want you as co-mentor for your star quality. Of
> course you won't have to do a thing, just identify for me a True Python
> Geek and she and I will take it from there.
>
> Here's the link in case you lost it:
>
> http://www.lispnyc.org/wiki.clp?page=PyCells
>
> :)
>
> peace, kenny
>
> ps. flaming aside, PyCells really would be amazingly good for Python.
> And so Google. (Now your job is on the line. <g>) k
Perhaps I'm missing something but what's the big deal about PyCells?
Here is 22-lines barebones implementation of spreadsheet in Python,
later I create 2 cells "a" and "b", "b" depends on a and evaluate all
the cells. The output is
a = negate(sin(pi/2)+one) = -2.0
b = negate(a)*10 = 20.0
=================== spreadsheet.py ==================
class Spreadsheet(dict):
def __init__(self, **kwd):
self.namespace = kwd
def __getitem__(self, cell_name):
item = self.namespace[cell_name]
if hasattr(item, "formula"):
return item()
return item
def evaluate(self, formula):
return eval(formula, self)
def cell(self, cell_name, formula):
"Create a cell defined by formula"
def evaluate_cell():
return self.evaluate(formula)
evaluate_cell.formula = formula
self.namespace[cell_name] = evaluate_cell
def cells(self):
"Yield all cells of the spreadsheet along with current values
and formulas"
for cell_name, value in self.namespace.items():
if not hasattr(value, "formula"):
continue
yield cell_name, self[cell_name], value.formula
import math
def negate(x):
return -x
sheet1 = Spreadsheet(one=1, sin=math.sin, pi=math.pi, negate=negate)
sheet1.cell("a", "negate(sin(pi/2)+one)")
sheet1.cell("b", "negate(a)*10")
for name, value, formula in sheet1.cells():
print name, "=", formula, "=", value
More information about the Python-list
mailing list