我正在制作一个简单的python脚本来处理一个表。我正在使用数组来存储单元格值。这是代码:
table =[]
hlen = input("Please enter the amount of columns n")
vlen = input("Please enter the amount of rows n")
curcol = 1
currow = 1
totcell = hlen*vlen
while (totcell >= curcol * currow):
str = input("Please input "+ str(curcol) +"," + str(currow))
table.append(str)
if (curcol >= hlen):
currow =+ 1
//Process Table
该程序运行甜蜜,要求第一个单元格为 1,1。一切都很好,直到代码在重新加载时停止。这是蟒蛇错误输出
Traceback (most recent call last):
File "./Evacuation.py", line 13, in <module>
str = input("Please input "+ str(curcol) +"," + str(currow))
TypeError: 'int' object is not callable
感谢您的任何帮助。
你正在使用你的变量名来隐藏内置str
:
str = input("Please input "+ str(curcol) +"," + str(currow))
第二次,你试图用str(currow)
打电话给str
,现在是一个int
说出它的名字!
此外,您使用的是Python 2,因此最好使用raw_input
而不是input
m = input("Please input "+ str(curcol) +"," + str(currow))
please use different name of variable not use 'str' because it is python default function for type casting
table =[]
hlen = input("Please enter the amount of columns n")
vlen = input("Please enter the amount of rows n")
curcol = 1
currow = 1
totcell = hlen*vlen
while (totcell >= curcol * currow):
m = input("Please input "+ str(curcol) +"," + str(currow))
table.append(m)
if (curcol >= hlen):
currow += 1
Please enter the amount of columns
5
Please enter the amount of rows
1
Please input 1,11
Please input 1,11
Please input 1,1
>>> ================================ RESTART ================================
>>>
>>>Please enter the amount of columns
>>>1
Please enter the amount of rows
1
Please input 1,12
see this program and run it .
您使用str
作为从输入返回int
的变量名称。当你使用 str(curcol) 和 str(currow) 时,Python 指的是它,而不是 Python 字符串函数。