472,784 Members | 836 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 software developers and data experts.

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 2484
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
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.