[英]ValueError: unsupported format character ']' (0x5d)
I'm trying to make irc bot with python.我正在尝试使用 python 制作 irc 机器人。 The bot will parse XML and paste its content on channel.
该机器人将解析 XML 并将其内容粘贴到频道上。 This is part of my code
这是我的代码的一部分
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)
defenderbar = 100 - attackerbar
attackertag = domi.getElementsByTagName('name')[1].toxml()
attacker = attackertag.replace('<name>','').replace('</name>','')
defendertag = domi.getElementsByTagName('name')[42].toxml()
defender = defendertag.replace('<name>','').replace('</name>','')
attackerpointtag = domi.getElementsByTagName('points')[1].toxml()
attackerpoint = attackerpointtag.replace('<points>','').replace('</points>','')
defenderpointtag = domi.getElementsByTagName('points')[6].toxml()
defenderpoint = defenderpointtag.replace('<points>','').replace('</points>','')
attackerdomtag = domi.getElementsByTagName('domination')[0].toxml()
attackerdom = attackerdomtag.replace('<domination>','').replace('</domination>','')
defenderdomtag = domi.getElementsByTagName('domination')[4].toxml()
defenderdom = defenderdomtag.replace('<domination>','').replace('</domination>','')
result = 'Div.1 :: %s [ %s p ] [ %s% ] [ %s Dom ] <--> [ %s Dom ] [ %s% ] [ %s p ] %s ::' % (attacker, attackerpoint, attackerbar, attackerdom, defenderdom, defenderbar, defenderpoint, defender)
return result
and I got ValueError: unsupported format character ']' (0x5d).
我得到了
ValueError: unsupported format character ']' (0x5d).
I'm pretty sure I already close all [ ]我很确定我已经关闭了所有 [ ]
I tried change [ ] with () and the error is ValueError: unsupported format character ')' (0x5d)
我尝试用 () 更改 [],错误是
ValueError: unsupported format character ')' (0x5d)
Can anyone show me where I made a boo boo?谁能告诉我我在哪里制作了嘘声? Thank you
谢谢
You've twice put [ %s% ]
, which includes an extra % after the s
.您已经两次放置
[ %s% ]
,其中在s
之后包含一个额外的 % 。 Python interprets that as %]
, which is invalid. Python 将其解释为
%]
,这是无效的。
You have two %
characters in there that are not meant to be formatting characters.那里有两个
%
字符,它们不是格式化字符。 You need to double it to make Python ignore it:您需要将其加倍以使 Python 忽略它:
result = 'Div.1 :: %s [ %s p ] [ %s%% ] [ %s Dom ] <--> [ %s Dom ] [ %s%% ] [ %s p ] %s ::' % (attacker, attackerpoint, attackerbar, attackerdom, defenderdom, defenderbar, defenderpoint, defender)
QUESTION: Same Error at this line but I can't seem to find any %问题:这一行有同样的错误,但我似乎找不到任何 %
WHERE (@IncludeLeavers = 'Yes' OR @IncludeLeavers= 'No' AND Staff.IsCurrent = 1)
""",
params={
"IncludeLeavers": REPORT_OPTIONS["IncludeLeavers"][0]
})
Error on this line IncludeLeavers": REPORT_OPTIONS["IncludeLeavers"][0]
此行出现错误
IncludeLeavers": REPORT_OPTIONS["IncludeLeavers"][0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.