473,506 Members | 16,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A short question about non-ascii characters in list

js
>>print u"äöü"
äöü
>>print [u"äöü"]
[u'\xe4\xf6\xfc']

Python seems to treat non-ASCII chars in a list differently from the
one in the outside of a list.
I think this behavior is so inconvenient and actually makes debugging
work harder.

Is this an intentional? Is there any doc discussing about this?

Thanks.
Sep 17 '07 #1
3 1628
On Sep 17, 12:08 am, js <ebgs...@gmail.comwrote:
>print u"äöü"
äöü
>print [u"äöü"]

[u'\xe4\xf6\xfc']

Python seems to treat non-ASCII chars in a list differently from the
one in the outside of a list.
I think this behavior is so inconvenient and actually makes debugging
work harder.

Is this an intentional? Is there any doc discussing about this?
It's intentional. __str__ of a list uses the __repr__ of its
elements. This helps reduce confusion (e.g., between ['a', 'b, c']
and ['a, b', 'c']).

Sep 17 '07 #2
js
Thank you for your quick reply.
It's intentional. __str__ of a list uses the __repr__ of its
elements. This helps reduce confusion (e.g., between ['a', 'b, c']
and ['a, b', 'c']).
That's make sence, but it's also true that
sometimes we want to see the contents of a list in pretty format.
So for now I need to write and use crappy mylist like this.

class mylist(list):
def __str__(self):
return '[' + ', '.join(self) + ']'

l = mylist([u"äöü", u"äöü", u"äöü"])
print unicode(l)
very ugly, but just works.
Sep 17 '07 #3
js wrote:
That's make sence, but it's also true that
sometimes we want to see the contents of a list in pretty format.
That may be true, but most of the time not (at least not me) --
lists are no pretty printing instrument, but a container.
So for now I need to write and use crappy mylist like this.

class mylist(list):
def __str__(self):
return '[' + ', '.join(self) + ']'

l = mylist([u"äöü", u"äöü", u"äöü"])
print unicode(l)
very ugly, but just works.
What's wrong with

print ",".join(mylist)

? Also, the your solution isn't really "ugly" in my opinion.

Regards,
Björn

--
BOFH excuse #55:

Plumber mistook routing panel for decorative wall fixture

Sep 17 '07 #4

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

Similar topics

0
2684
by: Ethel Aardvark | last post by:
I am running a 9.0.1 database on a W2K server and have come across some strange behaviour with a SQL query. I have a query which runs in a PL/SQL cursor which has several PL/SQL variables used to...
99
8965
by: Glen Herrmannsfeldt | last post by:
I was compiling a program written by someone else about six years ago, and widely distributed at the time. It also includes makefiles for many different systems, so I know it has been compiled...
34
16607
by: Andy | last post by:
Hi, Are 1 through 4 defined behaviors in C? unsigned short i; unsigned long li; /* 32-bit wide */ 1. i = 65535 + 3; 2. i = 1 - 3; 3. li = (unsigned long)0xFFFFFFFF + 3; 4. li = 1...
3
2115
by: ram | last post by:
hi all, apart from readability, and not wanting the otherwise different statements to be assumed as one single loong statement what are the pros/cons of both snippets? i tried this out on a...
7
30256
by: Partho | last post by:
I have a float variable which I need to add to a short variable. How do I do this? Do I have to typecast or is there a way around? I tried typecasting the float to a short, but that gives me a 0 or...
15
2021
by: David Geering | last post by:
Is there any standard as to what a long and int mean or is it compiler dependent? Or furthermore architecture dependent? I know a short short long int isn't actually a recognised type, but if you...
40
3583
by: Spiros Bousbouras | last post by:
Do you have an example of an implementation where sizeof(short int) does not divide sizeof(int) or sizeof(int) does not divide sizeof(long int) or sizeof(long int) does not divide sizeof(long long...
3
1364
by: TS | last post by:
short x = 1; //this has build error saying missing conversion x = x + 2; Why can't you just add this? I guess the 1 is a literal that translates to an int32? How would I accomplish this...
8
13641
by: Phil Endecott | last post by:
Dear Experts, I'm surprised to find that std::max doesn't work (i.e. won't compile) if the arguments are not of exactly the same type, e.g. one is a short and the other is a long: #include...
3
6381
by: mathieu | last post by:
Could someone please tell me what is wrong with the following -ugly- piece of c++ code. Why when I explicititely set the template parameter my gcc compiler start getting confused: bla.cxx: In...
0
7370
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...
1
7021
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
5614
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,...
0
4701
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
3188
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
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1532
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 ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.