ascii character - removing chars from string
bruce
bedouglas at earthlink.net
Tue Jul 4 12:01:15 EDT 2006
update...
the error i'm getting...
>>>UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in
position 62: ordinal not in range(128)
is there a way i can tell/see what the exact char is at pos(62). i was
assuming that it's the hex \xa0.
i've done the s.replace('\xa0','') with no luck.
-bruce
-----Original Message-----
From: python-list-bounces+bedouglas=earthlink.net at python.org
[mailto:python-list-bounces+bedouglas=earthlink.net at python.org]On Behalf
Of Steven D'Aprano
Sent: Tuesday, July 04, 2006 8:45 AM
To: python-list at python.org
Subject: RE: ascii character - removing chars from string
On Tue, 04 Jul 2006 08:09:53 -0700, bruce wrote:
> simon...
>
> the issue that i'm seeing is not a result of simply using the
> 'string.replace' function. it appears that there's something else going on
> in the text....
>
> although i can see the nbsp in the file, the file is manipulated by a
number
> of other functions prior to me writing the information out to a file.
> somewhere the 'nbsp' is changed, so there's something else going on...
>
> however, the error i get indicates that the char 'u\xa0' is what's causing
> the issue..
As you have written it, that's not a character, it is a string of length
two. Did you perhaps mean the Unicode character u'\xa0'?
>>> len('u\xa0')
2
>>> len(u'\xa0')
1
> as far as i can determine, the string.replace can't/doesn't
> handle non-ascii chars. i'm still looking for a way to search/replace
> non-ascii chars...
Seems to work for me:
>>> c = u'\xa0'
>>> s = "hello " + c + " world"
>>> s
u'hello \xa0 world'
>>> s.replace(c, "?")
u'hello ? world'
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list