Early and late binding [was Re: what does 'a=b=c=[]' do]

alex23 wuwei23 at gmail.com
Sat Dec 24 08:43:20 EST 2011


On Dec 24, 2:15 am, Roy Smith <r... at panix.com> wrote:
> I know this is not quite the same thing, but it's interesting to look at
> what django (and mongoengine) do in their model definitions, prompted by
> your time.time() example.  You can do declare a model field something
> like:
>
> class Foo(models.Model):
>    timestamp = DateTimeField(default=datetime.utcnow)
>
> Now, when you create a Foo, if you don't supply a timestamp, it
> generates one by calling utcnow() for you.  Very handy.
>
> I'm not arguing that Python should do that, just pointing out an example
> of where late binding is nice.

There is absolutely nothing stopping you from writing functions now
with that behaviour. All Python functions are "early binding, late
calling" with their arguments, if you treat the arguments as callables
within the function body.






More information about the Python-list mailing list