[Tutor] Reset function

Jesse W jessw@loop.com
Wed, 8 Aug 2001 12:37:34 -0700


Dear Danny, et all,
Danny Yoo wrote:
> On Wed, 8 Aug 2001, Christopher Smith wrote:
> > Dear tutor,
> > 
> > I looked at the reset function presented recently to "purify the
> > namespace" before running a program (reset(vars())) and the last
> > line has me stumped.
> >  
> > Here's a simplified version: 
> > 
> > ###
> > def reset(namespace, user_safe_items=()):
> > 	for item in namespace.keys():
> > 		exec "del "+item in namespace
> 
> Try parsing it like this:
> 
>     exec ("del" + item)  in namespace
> 
> It might actually be better to write it like this to avoid confusion. 
> The 'in namespace' part is an optional part of the exec statement:
> 
>     http://www.python.org/doc/current/ref/exec.html
> 
> Good luck!
	Opps.  Yah, I should have realized that that "exec SomeCode in 
GlobalNamespace" thing was pretty obscure. Heck, I even had to 
look it up myself when I was writing the function!
	Thank you Danny, for explaining it to Chris. :-)
	Oh, and congratulations on your apotheosis. ;-) <grin>

						Cheers for the tutor list,
							Jesse F. Weinstein