3
我有問題,與Django外殼的奇怪行爲。我有這樣的代碼:內聯django外殼與python外殼的變量範圍
fields = ('name', 'description', 'long_description', 'foot_description')
a = 1
dict((field, a) for field in fields)
當我從蟒蛇運行殼它給我正確的字典。但是當我從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
我的問題很簡單:爲什麼?
似乎無法將其複製到我的外殼上。 :/ –
我可以在Django 1.3 IPython shell中複製這個錯誤。 – aychedee
@aychedee我不能......'Out [3]:{'description':1,'foot_description':1,'long_description':1,'name':1}' –