On Friday, January 28, 2011 9:32:13 AM UTC-5, Massimo Di Pierro wrote: 
>
> The fact is, you can do both. If you want the values to be evaluated 
> on insert, just do 
>
> Field(...,default=lambda: f()) 

 
What's the difference between using "default=lambda: f()" and just using 
"default=f" (assuming f is defined as a function somewhere)?
 
Is it just that "lambda: f()" guarantees you get something with type = 
FunctionType (so, for example, "default=lambda: datetime.datetime.now()" 
would work even though type(datetime.datetime.now) is BuiltinFunctionType 
and not FunctionType), or is there some other reason to prefer the lambda 
version?
 
It would be very helpful to discuss the use of functions as field defaults 
in the book (especially the issue of calling a function once at request time 
vs. passing a function to be called per record at insert time).
 
Thanks.
 
Anthony

Reply via email to