所有:內容)第一字典(後空
在Django中,我用這句話來獲取字典(q_a),但第一個字典()之後,第二個是空,蟒蛇是如何工作的爲了那個原因?
if request.method == "POST":
q_a = request.POST.iteritems()
print "type of q_a is %s" % q_a
print "first dict(q_a) : %s " % dict(q_a)
print "second dict(q_a): %s " % dict(q_a)
下面是打印輸出:
type of q_a is <generator object _iteritems at 0x10c97ac30>
first dict(q_a) : {u'csrfmiddlewaretoken': u'KQA7K6MCwZWFsXO59pAOYOMyD92O9tYq', u'\u5b66\u9662': u'ss', u'\u59d3\u540d': u'ww', u'\u624b\u673a\u53f7\u7801': u''}
second dict(q_a): {}
這是一個奇怪的空[iterator]案例(https://docs.python.org/2/glossary.html#term-iterator)。 –
'help(dict.iteritems)'。 – juanchopanza