On Thu, 4 May 2000, Fredrik Lundh wrote:
another approach is (simplified):
try: sys.stdout.write(x.encode(sys.stdout.encoding)) except AttributeError: sys.stdout.write(str(x))
Indeed, that would work to solve just this specific Unicode issue -- but there is a lot of flexibility and power to be gained from the general solution of putting a method on the stream object, as the example with the formatted list items showed. I think it is a good idea, for instance, to leave decisions about how to print Unicode up to the Unicode object, and not hardcode bits of it into print.
Guido, have you digested my earlier 'printout' suggestions?
"Old code doesn't die -- it just smells that way." -- Bill Frantz