我是python的新手并且正在努力理解这个错误意味着什么: TypeError:' int'对象不可调用
这是完整的代码:
import openpyxl, pprint,os
os.chdir('C:\Users\Shend_000\Documents\Py CWD')
wb=openpyxl.load_workbook('censuspopdata.xlsx')
sheet=wb.get_sheet_by_name('Population by Census Tract')
countyData={}
for row in range(2,sheet.max_row()):
state=sheet['B'+str(row)].value
county=sheet['C'+str(row)].value
pop=sheet['D'+str(row)].value
countyData.setdefault(state,{})
countyData[state].setdefault(county,{'tracts':0, 'pop':0})
countyData[state][county]['tracts']+=1
countyData[state][county]['pop']+=int(pop)
resultFile=open('census2010.py','w')
resultFile.write('allData= '+pprint.pformat(countyData))
resultFile.close()
print 'Done.'
答案 0 :(得分:1)
只需改变一下:
for row in range(2,sheet.max_row):
sheet.max_row
返回int
,您无法拨打int
。