Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.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 tal:条件未执行条件检查_Python_Zope_Template Tal_Zpt - Fatal编程技术网

Python tal:条件未执行条件检查

Python tal:条件未执行条件检查,python,zope,template-tal,zpt,Python,Zope,Template Tal,Zpt,我有下面的tal条件代码,理论上应该可以工作,但它不执行条件检查。窗体点击此条件,运行它,然后返回一个被0除的除法错误,而不是0 我故意处理不完整的数据,这是为了确保不会生成错误页,表中的单元格只显示0 <td style="text-align: right;"> <span tal:condition="python:result.sum_adt_out<>0"> <span tal:replace="p

我有下面的tal条件代码,理论上应该可以工作,但它不执行条件检查。窗体点击此条件,运行它,然后返回一个被0除的除法错误,而不是0

我故意处理不完整的数据,这是为了确保不会生成错误页,表中的单元格只显示0

<td style="text-align: right;">
        <span tal:condition="python:result.sum_adt_out<>0">
               <span tal:replace="python:'%.1f'%((float(result.sum_cenmn) or 0)/float(result.sum_adt_out))">currentindex</span></span>

        <span tal:condition="python:result.sum_adt_out==0">
               <span tal:replace="python:'%.1f'%(0.0)"></span></span>
</td>

当前索引

如果有人有任何想法,我们将不胜感激

如果
result.sum\u adt\u out
属性是字符串,则测试将失败

还请注意,Python中已弃用了
,请使用
=改为测试不平等性。您的模板经过简化,首先对值调用
float()
,以确保其为数字,然后变为:

<td style="text-align: right;" tal:define="sum_adt_out python:float(result.sum_adt_out)">
    <span tal:condition="sum_adt_out"
          tal:content="python:'%.1f' % (float(result.sum_cenmn)/sum_adt_out,)">currentindex</span>

    <span tal:condition="not:sum_adt_out">0.0</span>

</td>

当前索引
0