python : TypeError: 'str' object is not callable

python : TypeError: 'str' object is not callable

我有一个简单直接的问题 - 请查看代码:

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()

尝试使用 openpyxl 库的内置方法创建和保存输出文件。

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')