Reputation: 433
Im making a simple python script to process a table. I am using a array to store the cell values. Heres the code:
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
The program runs sweet, asking for the first cell at 1,1. All is well, until the code stops when reloading. Heres pythons error output
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
Thanks for any help.
Upvotes: 0
Views: 166
Reputation: 2286
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 .
Upvotes: 1
Reputation: 545
You are using str
as a variable name for the int
you are returning from the input. Python is referring to that when you use str(curcol) and str(currow), rather than the Python string function.
Upvotes: 0
Reputation: 23251
You're shadowing the built in str
with your variable name:
str = input("Please input "+ str(curcol) +"," + str(currow))
The second time around, with str(currow)
you're trying to call str
, which is now an int
Name it anything but that!
Also, you're in Python 2, so it's far preferred to use raw_input
instead of input
Upvotes: 2