我有(匿名)从 Python 2.6.8 中的值构造的哈希:
sys.stderr.write('#' + str(dictionary['Field 4']) + '#\n')
kpis_found.append(float(int(dictionary['Field 1']), 1) *
max(float(dictionary['Field 2']), 1) *
max(float(dictionary['Field 3']), 1) *
max(float(dictionary['Field 4']), 1) *
max(float(dictionary['Field 5']), 1))
我得到的输出是:
[Fri Jul 13 09:04:44 2012] [error] [client ::1] #3#
[Fri Jul 13 09:04:44 2012] [error] [client ::1] Traceback (most recent call last):
[Fri Jul 13 09:04:44 2012] [error] [client ::1] File "/Users/jonathan/mirror/civic/google_maps/index.cgi", line 357, in <module>
[Fri Jul 13 09:04:44 2012] [error] [client ::1] max(float(dictionary['Field 4']), 1) *
[Fri Jul 13 09:04:44 2012] [error] [client ::1] TypeError: float() takes at most 1 argument (2 given)
据我所知,CSV 文件产生(通常)可转换为整数的字符串,或(偶尔)可转换为浮点数的字符串。如果我遇到 NULL,那应该更容易诊断。调试输出似乎确认有问题的字段是“3”。
这是如何得到 TypeError 的?我已经遍历括号以确保我没有计算
max(float(foo, bar))
而是计算
max(float(foo), bar)
欢迎任何见解。