japanese encoding iso-2022-jp in python vs. perl

Ryan Ginstrom software at ginstrom.com
Tue Oct 23 09:00:19 EDT 2007


> On Behalf Of kettle
>   I am rather new to python, and am currently struggling with some
> encoding issues.  I have some utf-8-encoded text which I need to
> encode as iso-2022-jp before sending it out to the world. I am using
> python's encode functions:
> --
>  var = var.encode("iso-2022-jp", "replace")
>  print var
> --

Possibly silly question: Is that a utf-8 string, or Unicode?

print unicode(var, "utf8").encode("iso-2022-jp")

On my computer (Japanese XP), your string round-trips between utf-8 and
iso-2022-jp without problems.

Another possible thing to look at is whether your Python output terminal can
print Japanese OK. Does it choke when printing the string as Unicode?

Regards,
Ryan Ginstrom




More information about the Python-list mailing list