sI具有以下代码:
s = StoryCat.objects.filter(category=c)
ids=s.values_list('id',flat=True)
ids=list(ids)
str= json.dumps( ids )
return HttpResponse(str)当尝试使用python shell时,它运行得很好。当在视图函数中运行它时,我得到以下错误:
list()恰好接受2个参数(给定1个)
可能的问题是什么?
发布于 2011-07-19 11:01:07
已在本地作用域中重写列表内置。如果您真的想使用list(),下面是一个解决方法的示例:
def list(a, b): pass # somewhere list is redefined
try:
c = list() # so this will fail
except TypeError as e:
print "TypeError:", e # with this error
from __builtin__ import list as lst # but we can get back the list builtin
c = lst() # and use it without overriding the local version of list
print c在您的示例中,最小的更改是将ids=list(ids)替换为
ids = __import__('__builtin__').list(ids)这根本不会改变您的命名空间,但会让我感到悲伤。
编辑:查看@Alex-Laskin的评论,了解更简单的一次性方法。
https://stackoverflow.com/questions/6741748
复制相似问题