473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

how to make format operator % work with unicode as expected

I am using things like "%-20s%-60s%-10s" in tkinter listbox to make it look
like a table, with mono sized font like lucie system. But this does not work
with data contains "Les misérables", because it is unicode, and one byte is
not neccessary one character. Now how can I resolve this issue?

My issue is "how to make format operator % work with unicode as expected",
and has nothing to do with tkinter. If I want to use a table widget or
something, I can. But that's not the question.

Jan 27 '08 #1
5 2911
I probably should mention that what I want is to make all parts of the
string aligned, and look like table. I am not looking for other ways to make
it table-alike, but only interested in making % work with unicode -counting
characters not bytes...

Jan 27 '08 #2
On Sun, 27 Jan 2008 04:06:45 +0000, Peter Pei wrote:
I probably should mention that what I want is to make all parts of the
string aligned, and look like table. I am not looking for other ways to
make it table-alike, but only interested in making % work with unicode
-counting characters not bytes...
% already works with unicode. Just give it unicode arguments:

>>print u"x y z %s 1 2 3" % u"Les misérables"
x y z Les misérables 1 2 3
--
Steven
Jan 27 '08 #3
For sure I can calculate the number of characters and do the padding myself,
but what's the point, and i surely hope that python does it for me.
============
"Peter Pei" <ya****@telus.comwrote in message
news:cjTmj.43610$fj2.37903@edtnps82...
>I am using things like "%-20s%-60s%-10s" in tkinter listbox to make it look
like a table, with mono sized font like lucie system. But this does not
work with data contains "Les misérables", because it is unicode, and one
byte is not neccessary one character. Now how can I resolve this issue?

My issue is "how to make format operator % work with unicode as expected",
and has nothing to do with tkinter. If I want to use a table widget or
something, I can. But that's not the question.
Jan 27 '08 #4
On Jan 27, 3:06 pm, "Peter Pei" <yan...@telus.comwrote:
I probably should mention that what I want is to make all parts of the
string aligned, and look like table. I am not looking for other ways to make
it table-alike, but only interested in making % work with unicode -counting
characters not bytes...
Can you show some *code* that demonstrates the alleged problem?
E.g. len("<some format>" % some_unicode) != expected_len

Reading this may help:
http://www.chiark.greenend.org.uk/~sgtatham/bugs.html

Jan 27 '08 #5
Peter Pei schrieb:
I am using things like "%-20s%-60s%-10s" in tkinter listbox to make it
look like a table, with mono sized font like lucie system. But this does
not work with data contains "Les misérables", because it is unicode, and
one byte is not neccessary one character. Now how can I resolve this issue?
By learning that unicode is not UTF-8, instead of insulting others of
being incompetent.
Diezz
Jan 27 '08 #6

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

Similar topics

30
by: | last post by:
I have not posted to comp.lang.c++ (or comp.lang.c++.moderated) before. In general when I have a C++ question I look for answers in "The C++ Programming Language, Third Edition" by Stroustrup....
2
by: Bernd Lambertz | last post by:
I have a problem with bcp and format files. We changed our databases from varchar to nvarchar to support unicode. No problems so fare with that. It is working fine. But now I need a format...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
22
by: Filipe | last post by:
Hi all, I'm starting to learn python but am having some difficulties with how it handles the encoding of data I'm reading from a database. I'm using pymssql to access data stored in a SqlServer...
1
by: Dennis Benzinger | last post by:
Is there a library with a strftime replacement which supports Unicode format strings? Bye, Dennis
7
by: Jim Langston | last post by:
What I want to do is have an operator= accept a template variable. I will have some classes which all will contain an instance of a different class. I want an operator= in yet a 3rd class to...
19
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; ...
16
by: Norman Diamond | last post by:
In an antique obsolete version of MFC, a CString expression could be subscripted in order to retrieve one element. Visual Studio 2005 defines CSimpleStringT::operator. At first glance it looks...
4
by: abendstund | last post by:
Hi, I have the following code and trouble with ambiguity due to operator overloading.. The code is also at http://paste.nn-d.de/441 snip>>
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...

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.