Bad programming style?

Carel Fellinger cfelling at iae.nl
Fri Dec 24 16:00:51 EST 1999


Alex Martelli <Alex.Martelli at think3.com> wrote:
> Carel writes:

>> Why not use the following:
>> 
>> >>> locals()['r'] = 'ff'
>> >>> print r
>> ff
>> 
> Uh, perhaps because the docs specifically tell you not to...?-)

Oeps, I've never been a obedient cityzen, but I think it's time
to straighten up my act then:)

> Reference puts it; I don't see how it could be clearer.

It could be clearer by not working:)

> I think this "feature" makes a good case for something I

for a moment I thought you ment the use of locals() in this way.
But elas, you were only after forcing me to give up this good
looking though unsafe idiom:(

> was wishing for since very early on in my (not yet very
> long:-) Python involvement -- a way to "lock" a mapping
> so that attempts to write to it will fail *non*-silently, i.e.,
> raise exceptions.  If such a 'locked' state was available,
> I imagine locals() would make use of it, preventing such
> erroneous usage.

So now that all namespaces are locked:) what is the approved way
of changing names? In classes we have instance.__dict__, but if
I remember correctly somewhere in the docs one is warned that
namespaces need not be implemented with dict. Can't find where it
said so, might wel have been read in some dreamlike state.
In functions and modules we only have locals(), right?
Do I really have to switch to exec?
-- 
groetjes, carel



More information about the Python-list mailing list