472,139 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,139 software developers and data experts.

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 5672
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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.