简体   繁体   中英

python : TypeError: 'str' object is not callable

I've got a simple, straight forward question - please look at the code :

import openpyxl
import warnings

warnings.simplefilter("ignore")

preq   = openpyxl.load_workbook('/Users/Ians/Desktop/_complete.xlsx')
preqWb = preq.get_sheet_names()
preqAS = preq.get_sheet_by_name(preqWb[0])
newRwa = open('/Users/Ians/Desktop/newRwa.xlsx','w')
for i in range(2, 101):
    a=preqAS['A'+str(i)].value <==== correct value printed
    b=preqAS['B'+str(i)].value <==== correct value printed
    newRwa.write(a,b)   <=========== error line TypeError: 'str' object is not callable

newRwa.close()

Try creating and saving the output file using the openpyxl library's inbuilt methods.

from openpyxl import Workbook

newRwa = Workbook()
ws1 = newRwa.active
for i in range(2,101):
    a = preqAS['A'+str(i)].value
    b = preqAS['B'+str(i)].value
    ws1.append([a, b])

newRa.save(filename='/Users/Ians/Desktop/newRwa.xlsx')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM