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 2 5811
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
"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 misunderstandin g. The word is "integer", not
"interger".
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michael Weir |
last post by:
I'm sure this is a very simple thing to do, once you know how to do it, but
I am having no fun at all trying to write utf-8 strings to a unicode file.
Does anyone have a couple of lines of code that
- opens a file appropriately for output
- writes to this file
Thanks very much.
Michael Weir
|
by: Guilherme Salgado |
last post by:
Hi there,
I have a python source file encoded in unicode(utf-8) with some
iso8859-1 strings. I've encoded this file as utf-8 in the hope that
python will understand these strings as unicode (<type 'unicode'>)
strings whithout the need to use unicode() or u"" on these strings. But
this didn't happen.
Am I expecting something that really shoudn't happen or we have a bug?
|
by: nico |
last post by:
In my python scripts, I use a lot of accented characters as I work in
french.
In order to do this, I put the line
# -*- coding: UTF-8 -*-
at the beginning of the script file.
Then, when I need to store accented characters in a string, I used to
prefix the literal string with 'u', like this:
mystring = u"prénom"
But if I understand well, prefixing a unicode string literal with 'u'
|
by: webdev |
last post by:
lo all,
some of the questions i'll ask below have most certainly been discussed
already, i just hope someone's kind enough to answer them again to help
me out..
so i started a python 2.3 script that grabs some web pages from the web,
regex parse the data and stores it localy to xml file for further use..
at first i had no problem using python minidom and everything concerning
|
by: Neil Schemenauer |
last post by:
python-dev@python.org.]
The PEP has been rewritten based on a suggestion by Guido to change
str() rather than adding a new built-in function. Based on my
testing, I believe the idea is feasible. It would be helpful if
people could test the patched Python with their own applications and
report any incompatibilities.
PEP: 349
| |
by: Jamie |
last post by:
I have a file that was written using Java and the file has unicode
strings. What is the best way to deal with these in C? The file
definition reads:
Data Field Description
CHAR File identifier (64 bytes corresponding to Unicode character
string padded with '0' Unicode characters.
CHAR File format version (32 bytes corresponding to Unicode
character string "x.y.z" where x, y, z are integers
corresponding to major, minor and...
|
by: gabor |
last post by:
hi,
from the documentation (http://docs.python.org/lib/os-file-dir.html) for
os.listdir:
"On Windows NT/2k/XP and Unix, if path is a Unicode object, the result
will be a list of Unicode objects."
i'm on Unix. (linux, ubuntu edgy)
|
by: Donn Ingle |
last post by:
Hello,
I hope someone can illuminate this situation for me.
Here's the nutshell:
1. On start I call locale.setlocale(locale.LC_ALL,''), the getlocale.
2. If this returns "C" or anything without 'utf8' in it, then things start
to go downhill:
2a. The app assumes unicode objects internally. i.e. Whenever there is
|
by: George Sakkis |
last post by:
It seems xml.etree.cElementTree.iterparse() is not unicode aware:
.... print elem.text
....
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 64, in __iter__
UnicodeEncodeError: 'ascii' codec can't encode characters in position
6-15: ordinal not in range(128)
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |