Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python,浮点错误:不支持+:“float”和“list”的操作数类型_Python_Python 3.x_Django_Django Models_Django Views - Fatal编程技术网

Python,浮点错误:不支持+:“float”和“list”的操作数类型

Python,浮点错误:不支持+:“float”和“list”的操作数类型,python,python-3.x,django,django-models,django-views,Python,Python 3.x,Django,Django Models,Django Views,我设置了以下类: class StatoPatrimoniale(models.Model): reference_date=models.DateField() cassa=models.DecimalField() 我设置了以下功能: def stato_patrimoniale(request): now=datetime.datetime.now() last_account_year=float(now.year)-1 list_diff=[]

我设置了以下类:

class StatoPatrimoniale(models.Model):
    reference_date=models.DateField()
    cassa=models.DecimalField()
我设置了以下功能:

def stato_patrimoniale(request):
    now=datetime.datetime.now()
    last_account_year=float(now.year)-1
    list_diff=[]
    list_diff = float(StatoPatrimoniale.objects.filter(reference_date__year=last_account_year).values_list('cassa')[0][0])
但是python给了我以下错误:

 unsupported operand type(s) for +: 'float' and 'list'
 list_diff = float(StatoPatrimoniale.objects.filter(reference_date__year=last_account_year).values_list('cassa')[0][0])

为什么??问题出在哪里?

我重现了错误:

TypeError: unsupported operand type(s) for +: 'float' and 'list'
但与上面共享的代码不同。相反,我提出:

list_diff = float() + list_diff
list_diff是一个列表,float是float,你不能这么做

换成

list_diff.append(float())

这可能是错误的,但完全是允许的,不是此错误的原因,我如何解决它?完整堆栈跟踪是什么样子的?从哪个意义上说?我想从Statopatrial类中提取cassa对象的值。它必须是十进制值。