2014-02-18 180 views
0

我正在製作一個簡單的python腳本來處理表格。我正在使用數組來存儲單元格值。 繼承人的代碼:'int'對象不可調用

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 

感謝您的任何幫助。

+4

不命名變量'str'(或'input'),你的問題就解決了...... –

+2

'currow = + 1'→'currow + = 1'? – Ryan

+0

使用'pylint'。它會吸取像這樣的常見問題。 – thefourtheye

回答

2

你遮蔽內置的str與您的變量名:

str = input("Please input "+ str(curcol) +"," + str(currow)) 

第二次左右,與str(currow)你想呼叫str,它現在是一個int

將它命名爲除此之外!

而且,你在Python 2,所以它是迄今爲止最好的raw_input代替input

0

您正在使用str作爲int你是從輸入返回變量名使用。 Python指的是當你使用str(curcol)和str(currow)時,而不是Python字符串函數。

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 .