我有问题,django shell 的奇怪行为。我有这个代码:
fields = ('name', 'description', 'long_description', 'foot_description')
a = 1
dict( (field, a) for field in fields)
当我从 python shell 运行它时,它给了我正确的字典。但是当我从 django shell 运行它时,我得到:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/usr/local/lib/python2.7/dist-packages/django/core/management/commands/shell.pyc in <module>()
----> 1 dict( (field, a) for field in fields)
/usr/local/lib/python2.7/dist-packages/django/core/management/commands/shell.pyc in <genexpr>((field,))
----> 1 dict( (field, a) for field in fields)
NameError: global name 'a' is not defined
我的问题很简单:为什么?