def minmax (actual, min, max):
print 'actual', actual, type(actual)
print 'min', min, type(min)
print 'max', max, type(max)
if actual:
if min(actual) < min:
min = min(actual1)
if max(actual) > max:
max = max(actual1)
return min, max
我想知道,为什么这段代码会产生以下错误? (我在Mac上使用Python 2.6.1)
actual [572, 2, 1] <type 'list'>
min 0 <type 'int'>
max 0 <type 'int'>
Traceback (most recent call last):
File "./bin/helixCSV.py", line 706, in <module>
main()
File "./bin/helixCSV.py", line 695, in main
create_final_results(final_result_path, seq_list, hl_fq_list, hl_no_list, strand_dist_list, helix_length_list, linker_occup_list, meta_list, HELIXDEF)
File "./bin/helixCSV.py", line 335, in create_final_results
result_dict[def_key]['5prime']['dist_min'], result_dict[def_key]['5prime']['dist_max'] = minmax(strand_dist_list[seq_no][def_key]['us'], result_dict[def_key]['5prime']['dist_min'], result_dict[def_key]['5prime']['dist_max'])
File "./bin/helixCSV.py", line 299, in minmax
if min(actual) < min:
TypeError: 'int' object is not callable
干杯 西蒙
答案 0 :(得分:12)
您正在使用min()
类型min
的{{1}}参数覆盖int
函数,这就是原因。将其重命名为其他内容。
def minmax (actual, min, max):
print 'actual', actual, type(actual)
print 'min', min, type(min)
print 'max', max, type(max)
if actual:
if min(actual) < min: #<- min(actual): python tries calling min(),
min = min(actual1) # min is int,
if max(actual) > max: # -> TypeError: 'int' object is not callable
max = max(actual1)
return min, max
答案 1 :(得分:10)
符号min
不能同时表示两件事(全局内置函数和局部变量)。