Dynamic Dictionary Creation

maney at pobox.com maney at pobox.com
Sun Dec 8 13:47:50 EST 2002


Carl Banks <imbosol at vt.edu> wrote:
> Bengt Richter wrote:
>> 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.

Well, no.  Data should not be global *because* it is unchanging.  Its
scope ought to be decided on the basis of needs-to-know.  As you have
observed, Python doesn't provide a good (read: efficent) way to place
this unchanging data in the scope it otherwise belongs in.  The design
with the global table is maybe just a little bit evil, and that mostly
only potentially evil, I think.

> 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.)

Is there some way to combine a local function with a defaulted argument
to hide the table inside function scope without the expense of
rebuilding the whole thing on every call?  I'm being dragged off to
lunch and haven't time in this margin to pursue the thought...

> Besides, most of the good reasons not to use globals don't apply when
> the data never changes.

I think this whole discussion has been clouded by trying to discuss
things at a superficial level.  Globals per se are neither good nor
bad; it's the coupling that they may allow that can be a problem.



More information about the Python-list mailing list