You should be able to use

default=f

Trunk version handles this better than 1.65.6 which has problems with
MethodType.

Yet if f is an instance with a a __call__ method, it will not call it.
For instancetype it will try serialize it with __str__.



On Jan 30, 1:36 pm, Anthony <abasta...@gmail.com> wrote:
> 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