def input_sentence():
sppc = BetterICP(grammar2)
with open("output.txt","w") as op:
with open("input.txt", "r") as ins:
array = []
temp = []
for line in ins:
array.append(line)
for a in array:
op.write(str(sppc.parse(a.split()))
我需要编写我的输出,我将从str(sppc.parse(a.split())
获取但不能将其写入文件
答案 0 :(得分:0)
你在op.write中错过了一个')'(str(sppc.parse(a.split()))
答案 1 :(得分:0)
似乎sppc.parse返回一个可迭代对象。尝试使用:
for a in array:
for b in sppc.parse(a.split())
op.write(str(b))