我有一个函数,它将在字符串元组中插入空格,以便所有字符串的len相等。我还有一个函数,可以处理字符串元组和一些格式化信息,并将它们组合为一个字符串元组#code for equal string lengthdef insertSpace(self,content): max = 0 for string in content: temp = len(string) if temp > max: max=temp retstring = ("",) for string in content: retstring = retstring + (" "*(max - len(string)+1,) return self.combine(retstring,content,bold=False,newline=False)#code for combinedef combine(self,leftside,rightside,bold=False,newline=False): if bold is True: bold = '<B>' boldend = '</B>' else: bold = '' boldend = '' if newline is True: newlinechar = '<br>' else: newlinechar = '' return tuple((bold +"{0}"+boldend+"{1}"+newlinechar).format(x,y) for x,y in zip(leftside,rightside))执行此脚本会导致File "mypythonfile.py", line 108return self.combine(retstring,content,bold=False,newline=False) ^SyntaxError: invalid syntax我试图将值存储在变量中,但没有任何改变。大概有点简单,但我看不到。
2 回答

12345678_0001
TA贡献1802条经验 获得超5个赞
您错过了)此行的结束语:
retstring = retstring + (" "*(max - len(string)+1,))
^
|
编辑:在您的代码:
>>> 'retstring = retstring + (" "*(max - len(string)+1,)'.count("(")
3
>>> 'retstring = retstring + (" "*(max - len(string)+1,)'.count(")")
2
添加回答
举报
0/150
提交
取消