unittest: Dynamically creating tests

Michele Simionato mis6 at pitt.edu
Thu Jun 12 10:20:26 EDT 2003


Peter Hansen <peter at engcorp.com> wrote in message news:<3EE79E36.961098DC at engcorp.com>...
> Michele Simionato wrote:
> > 
> > Steven Taschuk <staschuk at telusplanet.net> wrote in message news:<mailman.1055356374.23599.python-list at python.org>...
> > >
> > > There's also
> > >     globals()['foo'] = 'bar'
> > > and, of course, exec.
> > >
> > 
> > I seems to remember (from reading the standard library)
> > that assigning directly to globals() is not recommended; am
> > I correct ? What can go wrong with this?
> 
> Are you misremembering the part about assigning to locals()
> being very bad?  I thought assigning to globals() was fine 
> technically, whether there were stylistic concerns or not.
> 
> -Peter

Ha-a! It was "locals()", indeed:

locals()

      Update and return a dictionary representing the current local
symbol table. Warning: The contents of this dictionary should not be
modified; changes may not affect the values of local variables used by
the interpreter.

I misremembered, thanks for the correction,

               Michele




More information about the Python-list mailing list