RuntimeError: dictionary changed size during iteration

Terry Reedy tjreedy at udel.edu
Thu Jan 20 13:40:12 EST 2005


RE: RuntimeError: dictionary changed size during iteration
"Batista, Facundo" <FBatista at uniFON.com.ar> wrote

[Robert Brewer]
#- But not unexpected, since vars() returns a dictionary, and
#- binding 'e'
#- changes that dictionary while you are iterating over it.

>For me, the point is: vars() returns the local variables
> as a list or is a generator?

As the OP said, it returns a *dictionary*.  In particular:

>>> help(vars)
Help on built-in function vars:

vars(...)
    vars([object]) -> dictionary

    Without arguments, equivalent to locals().
    With an argument, equivalent to object.__dict__.

>In the docs don't say nothing about this.

You must be having a bad day ;-).  From Lib Ref 2.1 Built-in Functions:

      vars( [object])

Without arguments, return a dictionary corresponding to the current local 
symbol table. With a module, class or class instance object as argument (or 
anything else that has a __dict__ attribute), returns a dictionary 
corresponding to the object's symbol table. The returned dictionary should 
not be modified: the effects on the corresponding symbol table are 
undefined

Terry J. Reedy






More information about the Python-list mailing list