[Zope] Replacing an unicode string

Gus Gollings gus at commonground.com.au
Tue Aug 26 14:16:42 EDT 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Tuesday, August 26, 2003, at 07:02 AM, Dieter Maurer wrote:
> Florian Reiser wrote at 2003-8-25 11:24 +0200:
>> I have an unicode string:
>>
>> text = u'ABC<EURO>'
>>
>> Now I want to do a replacement of the string u'<EURO>' to u'\u20ac'
>> (this is the euro sign).
>> When I type
>>
>> text = text.replace(u'<EURO>', u'\u20ac')
>>
>> nothing happens, the string is still u'ABC<EURO>'
>> How can I replace the tag '<EURO>' and insert the euro sign instead?
>
> Works for me: Python 2.1.3. Done in an interactive interpreter.

I think the heart of the problem is not the unicode string replace, but 
the conversion of a double-byte character (the euro sign - €) into 
ASCII:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 >>> print  u'\u20ac'

Traceback (most recent call last):
   File "<stdin>", line 1, in ?
UnicodeError: ASCII encoding error: ordinal not in range(128)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Would it be possible to use the HTML entity for the Euro currency sign 
instead of a unicode string?

"€" HTML Entity Values:
name:    &euro;
Decimal: &#8364;
Hex:     &#x20AC;

Regards,

Gus
- -
http://commongroundgroup.com
+613 9398 8000


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (Darwin)

iD8DBQE/StEeFpx6ZDMgHYARAmKPAKCkuk7H/TbBsbzzLwz3NMOwTsi0PwCdGdev
vmFSwTJ/dcdda8It4XpN3pw=
=+2WY
-----END PGP SIGNATURE-----




More information about the Zope mailing list