Reputation: 259
I'm trying to make irc bot with python. The bot will parse XML and paste its content on channel. 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).
I'm pretty sure I already close all [ ]
I tried change [ ] with () and the error is ValueError: unsupported format character ')' (0x5d)
Can anyone show me where I made a boo boo ? Thank you
Upvotes: 1
Views: 3063
Reputation: 1121864
You have two %
characters in there that are not meant to be formatting characters. You need to double it to make Python ignore it:
result = 'Div.1 :: %s [ %s p ] [ %s%% ] [ %s Dom ] <--> [ %s Dom ] [ %s%% ] [ %s p ] %s ::' % (attacker, attackerpoint, attackerbar, attackerdom, defenderdom, defenderbar, defenderpoint, defender)
Upvotes: 3
Reputation: 599600
You've twice put [ %s% ]
, which includes an extra % after the s
. Python interprets that as %]
, which is invalid.
Upvotes: 4