steven... when you have the >>>u'hello ? world'<< in your interpreter/output, is the 'u' indicating that what you're displaying is unicode?
i pretty much tried what you have in the replace.. and i got the same error regarding the unicodedecode error... -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Steven D'Aprano Sent: Tuesday, July 04, 2006 8:45 AM To: python-list@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 -- http://mail.python.org/mailman/listinfo/python-list