Python RuntimeError: dictionary changed size during iteration

运行下面代码,报如下错误

for name in globals():
    print(name)

 

解决办法是:将待遍历的对象转换成列表

for name in list(globals()):
    print(name)

 

posted @ 2023-09-25 22:35  limalove  阅读(46)  评论(0)    收藏  举报