[Tutor] loops to assign variables

Alan Gauld alan.gauld at freenet.co.uk
Sun Jul 23 12:16:28 CEST 2006


I've been on vacation so missed the start of this, apologies 
if i'm missing a point somewhere but...

> Ah. I see.  A copy, eh?  Or, at least a new dictionary separate
> from the "real" namespace.  OK.  I don't know why locals() returns
> a copy as opposed to the original, 

What else can it do?
When you enter a function you enter a new namespace.
It starts out containing the global names and any parameters 
to the function then adds new names as they are created 
plus overrides any global names that get replaced with 
local versions.

It can only do that if it is working on a copy of the global 
namespace to start with otherwise it would be polluting the 
global namespace with local functon versions and in a 
multithreaded environment creating havoc across threads!...

I hope I haven't missed the point and have added some 
clarification, if not forgive me for butting in late! :-)

Alan G.



More information about the Tutor mailing list