vars()在列表理解中使用时,与python 3相比,在python 3中的行为有所不同
Python 3:
In [1]: def hello(test=None):
...: print(vars())
...: print([vars() for i in [0]])
...:
In [2]: hello()
{'test': None}
[{'.0': <tuple_iterator object at 0x7fae943e6b38>, 'i': 0}]
Python 2:
In [1]: def hello(test=None):
...: print(vars())
...: print([vars() for i in [0]])
...:
In [2]: hello()
{'test': None}
[{'test': None, 'i': 0}]
tuple_iterator对象是一个空列表,没有'test'