1
我對編程非常陌生,python是我的第一個編程語言,所以請好。我已經運行下面的代碼位:TypeError:不支持的操作數類型爲 - :'str'和'int'Python
searchmovie = raw_input("What movie would you like to rent?\n").lower()
searchindex = dvds.index(searchmovie)
r = csv.reader(open('dvd_info.csv'))
lines = [l for l in r]
currentvalue = lines[searchindex][2]
lines[searchindex][2] = currentvalue - 1
writer = csv.writer(open('tmp.csv', 'w'))
writer.writerows(lines)
,我已經gotton錯誤:
lines[searchindex][2] = currentvalue - 1
TypeError: unsupported operand type(s) for -: 'str' and 'int'
我在做什麼錯?
您的'currentvalue'是一個字符串,您需要先將其轉換爲'int'。 – AKS
行'[searchindex] [2] = str(int(currentvalue) - 1)' – ozgur
非常感謝!阿哈對不起,這是一個非常業餘的問題。 – Rab2233