简体   繁体   English

ValueError: 不支持的格式字符 ']' (0x5d)

[英]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.

相关问题 ValueError:不支持的格式字符&#39; - ValueError: unsupported format character ' %d由python和附加ValueError:索引2处不支持的格式字符&#39;O&#39;(0x4f) - %d by python and addition ValueError: unsupported format character 'O' (0x4f) at index 2 ValueError:索引处不支持的格式字符&#39;{&#39;(0x7b) - ValueError: unsupported format character '{' (0x7b) at index ValueError:索引3处不支持的格式字符&#39;&lt;&#39;(0x3c) - ValueError: unsupported format character '<' (0x3c) at index 3 ValueError:使用dict格式化时,格式字符\\&#39;“ \\&#39;(0x22)不支持 - ValueError: unsupported format character \'"\' (0x22) when formatting with dict ValueError: 不支持的格式字符 &#39;p&#39; (0x70) 在索引 7 - ValueError: unsupported format character 'p' (0x70) at index 7 Python,Django:ValueError:索引3处不受支持的格式字符&#39;(&#39;(0x28) - Python, Django: ValueError: unsupported format character '(' (0x28) at index 3 ValueError:索引79处不支持的格式字符&#39;a&#39;(0x61) - ValueError: unsupported format character 'a' (0x61) at index 79 ValueError:定义字典中不支持的格式字符'{'(0x7b) - ValueError: unsupported format character '{' (0x7b) in defining dictionary ValueError:不支持的格式字符&#39;C&#39;(0x43) - ValueError: unsupported format character 'C' (0x43)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM