【发布时间】:2013-08-03 14:18:41
【问题描述】:
我有问题,django shell 的奇怪行为。我有这个代码:
fields = ('name', 'description', 'long_description', 'foot_description')
a = 1
dict( (field, a) for field in fields)
当我从 python shell 运行它时,它给了我正确的 dict。但是当我从 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
我的问题很简单:为什么?
【问题讨论】:
-
似乎无法在我的 shell 上复制它。 ://
-
我可以在 Django 1.3 IPython shell 中复制这个错误。
-
@aychedee 我不能……
Out[3]: {'description': 1, 'foot_description': 1, 'long_description': 1, 'name': 1} -
@OP:你用的是什么版本?我无法在 Django 1.5 上复制它。
-
我可以在 Django 1.4.1 IPython shell 和 Django IPython shell 1.3.7 上复制它。
标签: python django django-shell