为了账号安全,请及时绑定邮箱和手机立即绑定

SyntaxError:语法无效(Python 3.2)

SyntaxError:语法无效(Python 3.2)

料青山看我应如是 2021-03-22 17:23:18
我有一个函数,它将在字符串元组中插入空格,以便所有字符串的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 + ("&nbsp;"*(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 + ("&nbsp;"*(max - len(string)+1,))

                                                        ^ 

                                                        | 

编辑:在您的代码:


>>> 'retstring = retstring + ("&nbsp;"*(max - len(string)+1,)'.count("(")

3

>>> 'retstring = retstring + ("&nbsp;"*(max - len(string)+1,)'.count(")")

2


查看完整回答
反对 回复 2021-03-23
  • 2 回答
  • 0 关注
  • 196 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号