In cso.data.__init__.py
I'm trying to do following:
from cso.data._features import * # import sumbodule
for k, v in globals().items():
if isinstance(v, entity):# entity is some type
print(k,v)
To my surprise, I get:
Traceback (most recent call last):
File "X:\Programming\workspaceEclipse\PyCommonSence\src\cso\data\__init__.py", line 20, in <module>
from cso.data._features import *
File "X:\Programming\workspaceEclipse\PyCommonSence\src\cso\data\__init__.py", line 49, in <module>
for k, v in globals().items():
RuntimeError: dictionary changed size during iteration
For some reason it tries to modify the iterated globals somehow. How can it be ?
Is there another better way to list all variables in the form name: value
from all modules in the package?
The list comprehension equivalent works without error, but prints twice:
print([ (k, v) for k, v in globals().items() if isinstance(v, entity)])
What is happening here?