Unicode coercion not the same as ASCII

Dale Strickland-Clark dale at out-think.NOSPAMco.uk
Sat Dec 9 15:12:04 CET 2000

Is there a particularly good reason for this apparently inconsistent behaviour?

>>> str(123)
>>> unicode(123)
Traceback (innermost last):
  File "<interactive input>", line 1, in ?
TypeError: coercing to Unicode: need string or buffer, int found

To get a number represented as a Unicode string, do I really need to do this?

>>> unicode(str(123))

When working in ASCII it is handy to be able to stuff anything into str() to get a readable
representation of it. 

When working in Unicode, you have to test datatypes and treat them differently which isn't very

Dale Strickland-Clark
Out-Think Ltd
Business Technology Consultants

More information about the Python-list mailing list