我有一個函數,它將在字符串元組中插入空格,以便所有字符串的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
提交
取消