我正在尝试用python制作irc机器人。该机器人将解析XML并将其内容粘贴到频道上。这是我的代码的一部分
f = open("1.xml")
data = f.read()
f.close()
domi = parseString(data)
attackerbartag = domi.getElementsByTagName('bar')[0].toxml()
attackerbar = attackerbartag.replace('<bar>','').replace('</bar>','')
attackerbar = round(float(attackerbar)2)
deffenderbar = 100 - attackerbar
attackertag = domi.getElementsByTagName('name')[1].toxml()
attacker = attackertag.replace('<name>','').replace('</name>','')
deffendertag = domi.getElementsByTagName('name')[42].toxml()
deffender = deffendertag.replace('<name>','').replace('</name>','')
attackerpointtag = domi.getElementsByTagName('points')[1].toxml()
attackerpoint = attackerpointtag.replace('<points>','').replace('</points>','')
deffenderpointtag = domi.getElementsByTagName('points')[6].toxml()
deffenderpoint = deffenderpointtag.replace('<points>','').replace('</points>','')
attackerdomtag = domi.getElementsByTagName('domination')[0].toxml()
attackerdom = attackerdomtag.replace('<domination>','').replace('</domination>','')
deffenderdomtag = domi.getElementsByTagName('domination')[4].toxml()
deffenderdom = deffenderdomtag.replace('<domination>','').replace('</domination>','')
result = 'Div.1 :: %s [ %s p ] [ %s% ] [ %s Dom ] <--> [ %s Dom ] [ %s% ] [ %s p ] %s ::' % (attacker, attackerpoint, attackerbar, attackerdom, deffenderdom, deffenderbar, deffenderpoint, deffender)
return result
我得到了
ValueError: unsupported format character ']' (0x5d).
我很确定我已经关闭了所有[]
我尝试使用()更改[],错误为
ValueError: unsupported format character ')' (0x5d)
谁能告诉我我在哪里做嘘声?
谢谢
最佳答案
您已经两次放置了[ %s% ]
,其中在s
之后包含一个额外的%。 Python将其解释为%]
,这是无效的。
关于python - ValueError:不支持的格式字符']'(0x5d),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12586544/