global and None

Francis Avila francisgavila at yahoo.com
Tue Dec 23 17:40:50 EST 2003


Paul McGuire wrote in message ...
>"Francis Avila" <francisgavila at yahoo.com> wrote in message
>news:vug3s0pa1q1sa3 at corp.supernews.com...
>> Leo Yee wrote in message ...
>> >My purpose is to init g. This is very useful when we cannot construct a
>> >global variable.
>>
>> Like when? And why?
>>
>
>One reason is to do late construction/initialization, or lazy
>initialization.  If an object is very time-consuming to construct, don't
>create it at import time, wait until it is actually used.  Once created,
>save it in a global so that you don't have to re-create it every time.

Hmm, I hadn't thought of that.  If this is a use case, aren't the
restrictions placed on global in the specs rather encumbering, and should be
removed? (Well, except for for-loop targets and formal parameters.)  As it
is, to comply, you'd have to use a temporary name for construction, and then
assign to the global name.
--
Francis Avila





More information about the Python-list mailing list