473,467 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to wrap a Japanese text in Python

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.

Thanks in advance.

Regards,
Prashant

Jun 7 '07 #1
2 2517
On Jun 7, 5:12 am, pr****************@gmail.com wrote:
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.
First of all you should move message.decode('utf-8') call out of "if"
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
for me:

# -*- coding: utf-8 -*-
sample=u"""
"""

import textwrap
for line in textwrap.wrap(sample, 6):
print line
--------------------------------
Result:




Can you post a short example that clearly demonstrates the problem?

-- Leo
Jun 8 '07 #2
On Jun 8, 2:24 am, Leo Kislov <Leo.Kis...@gmail.comwrote:
On Jun 7, 5:12 am, prashantkisanpa...@gmail.com wrote:
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.

First of all you should move message.decode('utf-8') call out of "if"
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
for me:

# -*- coding: utf-8 -*-
sample=u"""
"""

import textwrap
for line in textwrap.wrap(sample, 6):
print line
--------------------------------
Result:
Oh, my. IE7 and/or Google groups ate my Japanese text :( But I hope
you've got the idea: try to work on a small example python program
in a unicode-friendly IDE like for example IDLE.
Can you post a short example that clearly demonstrates the problem?
This question is still valid.

-- Leo.

Jun 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David Thomas | last post by:
Hi there, a while ago, I posted a question regarding reading japanese text from a text file. Well, since I solved the problem, I thought I'd post my solution for the benefit of other people with...
2
by: Robert M. Gary | last post by:
I'm on a Solaris 9 Japanese machine w/ an Ultra 5 Sparc CPU. I'm using Xerces 2.6 DOM I've got a document in UTF-8 format.. <?xml version="1.0" encoding="UTF-8"?>...
3
by: Benoit Martin | last post by:
in my windows app, I have some japanese text that I load from a text file and display on a label. No matter what type of encoding I try to use on the text file, the text always comes up as a bunch...
11
by: prats | last post by:
I want to write a GUI application in PYTHON using QT. This application is supposed to take in Japanese characters. I am using PyQt as the wrapper for using QT from python. I am able to take input...
12
by: paulgor | last post by:
Hi, May be it's a know issue but my search brought nothing... We have static HTML files with Japanese text in UTF-8 encoding - it's on-line Help for our application, so there are no Web...
4
by: DL | last post by:
Hi, Our school has an application in which : - Teachers enter comments through a web interface built in asp (not asp.net). - Comments are stored in a SQL server 2000 (in a nText field) -...
6
by: Victor | last post by:
Hi all i have a css question about how to wrap a long text by using css. for example I have a very long text like "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd" there...
12
by: Steve Howell | last post by:
The never-ending debate about PEP 3131 got me thinking about natural languages with respect to Python, and I have a bunch of mostly simple observations (some factual, some anecdotal). I present...
4
by: kettle | last post by:
Hi, 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.