我制作一个简单的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。一切都很好,直到代码在重新加载时停止。 Heres pythons错误输出
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
感谢您的帮助。
答案 0 :(得分:2)
您使用变量名隐藏了内置str
:
str = input("Please input "+ str(curcol) +"," + str(currow))
第二次,str(currow)
您尝试调用 str
,现在是int
将其命名为以外的任何内容!
另外,您使用的是Python 2,因此最好使用raw_input
代替input
答案 1 :(得分:1)
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 .
答案 2 :(得分:0)
您正在使用str
作为您从输入中返回的int
的变量名称。 Python指的是当你使用str(curcol)和str(currow)时,而不是Python字符串函数。