I am newbie programmer trying to make an irc bot that parse xml and paste its content on a channel. Usually i find my answer on google, but this time i can’t find my answer.
JavaScript
x
5
1
q0tag = dom.getElementsByTagName('hit')[0].toxml()
2
q0 = q0tag.replace('<hit>','').replace('</hit>','')
3
4
q1 = (q0 * 1.2)
5
when i’m trying to multiply q0 it always showing
JavaScript
1
2
1
TypeError: can't multiply sequence by non-int of type 'float'.
2
Im trying to make q0 int or float but it just make another error
JavaScript
1
2
1
AttributeError: 'NoneType' object has no attribute 'replace'
2
q0 value is a round number without decimal.
Advertisement
Answer
Your q0 value is still a string. This is basically what you’re doing:
JavaScript
1
6
1
>>> q0 = '3'
2
>>> q1 = (q0 * 1.2)
3
Traceback (most recent call last):
4
File "<stdin>", line 1, in <module>
5
TypeError: can't multiply sequence by non-int of type 'float'
6
To fix it, convert the string to a number first:
JavaScript
1
4
1
>>> q1 = (float(q0) * 1.2)
2
>>> q1
3
3.5999999999999996
4
You might also want to look into the lxml and BeautifulSoup modules for parsing XML.