On Jun 7, 5:12 am, email@example.com wrote:
First of all you should move message.decode('utf-8') call out of "if"
> Hi All,
> I am trying to wrap a japanese text in Python, by the following code.
> if len(message) > 54:
> message = message.decode("UTF8")
> strlist = textwrap.wrap(message,54)
> After this I am wirting it to you a CAD Software window. While
> displaying in this window some Japanese characters at the end of the
> line & some at the begining of the line are not displayed at all.
> Meaning the text wrapping is not happening correctly.
> Can any body please help me out in resolving this problem.
and you don't need "if" anyway because if the line is less than 54
textwrap won't touch it:
message = message.decode('utf-8')
strlist = textwrap.wrap(message, 54)
I don't know Japanese but the following example *seems* to work fine
# -*- coding: utf-8 -*-
for line in textwrap.wrap(sample, 6):
Can you post a short example that clearly demonstrates the problem?