Dynamic Dictionary Creation

Bengt Richter bokr at oz.net
Sat Dec 7 12:42:13 EST 2002


On Fri, 6 Dec 2002 23:18:32 -0500, Carl Banks <imbosol at vt.edu> wrote:

>Bengt Richter wrote:
>> On Fri, 06 Dec 2002 11:37:07 -0700, Bob van der Poel <bvdpoel at kootenay.com> wrote:
>>>I suppose I could make the table global and avoid this?
>>>
>> Yes, but if the table is only used in the function, that's not nice.
>> There are several alternatives you could use.
>
>
>I wouldn't totally agree with this.  Data that never changes ought to
>be global.
I'm not sure how you mean that. To me <constant> and <global> are are
pretty orthogonal concepts.

>
>Some languages allow you to define data that exists globally, but has
>only local scope (for example, in C you can use "static" declarations
>inside a function).  Whenever you can do this, I agree it's nicer to
>put it inside the function.  But because you can't in Python, I think
>it's "nicest" to just make it global.  (Not necessarily fastest.)
>
>Besides, most of the good reasons not to use globals don't apply when
>the data never changes.
Except that the risk of name collision grows the more you put in a given
name space. That's the primary reason for me. Of course, global is relative,
so if you have a small module its global name space does encapsulate, and
using leading underscores for global names therein does prevent helter-skelter
name imports.

ISTM where you put things is a kind of subliminal concept documentation also.
I.e., it hints at how you are thinking of the things in relation to the rest.

Regards,
Bengt Richter



More information about the Python-list mailing list