Math with unicode strings?

erikcw erikwickstrom at gmail.com
Mon Apr 2 15:09:21 EDT 2007


Hi,

I'm parsing xml data with xml.sax and I need to perform some
arithmetic on some of the xml attributes.  The problem is they are all
being "extracted" as unicode strings, so whenever I try to perform
math operations on the variables, I get this error:

cr[0] = data['cls1']/data['ims1'];
TypeError: unsupported operand type(s) for /: 'unicode' and 'unicode'

What do I need to do to extract the intergers from these unicode
strings (or better yet, parse them as intergers in the first place.).
I'm using the SAX method attrs.get('cls1',"") to parse the xml.  Can I
"cast" the string into an interger?

Thanks!
Erik




More information about the Python-list mailing list