469,915 Members | 2,686 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,915 developers. It's quick & easy.

Math with unicode strings?

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

Apr 2 '07 #1
2 5567
On Apr 2, 10:09 pm, "erikcw" <erikwickst...@gmail.comwrote:
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
int(u'123') == 123
float(u'123') == 123.0

Apr 2 '07 #2
"erikcw" <er***********@gmail.comwrote:
>
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?
When I see a typo once, I figure it's a typo, but when I see it three
times, I figure it is a misunderstanding. The word is "integer", not
"interger".
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Apr 4 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Michael Weir | last post: by
4 posts views Thread by Guilherme Salgado | last post: by
6 posts views Thread by nico | last post: by
4 posts views Thread by webdev | last post: by
2 posts views Thread by Neil Schemenauer | last post: by
5 posts views Thread by Jamie | last post: by
13 posts views Thread by George Sakkis | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.