RuntimeError: dictionary changed size during iteration

Jack Diederich jack at performancedrivers.com
Wed Jan 19 16:01:04 EST 2005


On Wed, Jan 19, 2005 at 11:45:15PM +0300, Roman Suzi wrote:
> 
> I think, the behaviour below is misfeature:
> 
> >>> [e for e in vars()]
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> RuntimeError: dictionary changed size during iteration
> >>> e = None
> >>> [e for e in vars()]
> ['e', '__builtins__', 'rlcompleter', '__file__', '_[1]', 'atexit', '__name__',
> 'readline', '__doc__']
> 

Chalk it up as a lesson in the slightly different behavior of genexps

Python 2.4 (#2, Jan  8 2005, 20:18:03) 
[GCC 3.3.5 (Debian 1:3.3.5-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> list(e for e in vars())
['__builtins__', '__name__', '__doc__']
>>> [e for e in vars()]
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
RuntimeError: dictionary changed size during iteration

-Jack



More information about the Python-list mailing list