[Tutor] unicode help
Marilyn Davis
marilyn at pythontrainer.com
Sat May 28 23:06:04 CEST 2011
Hi,
I'm still on Python 2.6 and I'm trying to work some unicode handling.
I've spent some hours on this snippet of code, trying to follow PEP 0263,
since the error tells me to see it. I've tried other docs too and I am
still clueless.
The code works, except for the comment at the end.
I would be very grateful for some help.
#!/usr/bin/env python
'''Unicode handling for 2.6.
'''
class Currency(float):
def __str__(self):
value = self.__class__.symbol + float.__str__(self)
return value
class Yen(Currency):
symbol = unichr(165)
class Pound(Currency):
symbol = unichr(163)
def main():
y = Yen(100)
print unicode(y)
p = Pound(100)
print unicode(p)
main()
"""
¥100.0
£100.0
"""
More information about the Tutor
mailing list