473,394 Members | 1,693 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,394 software developers and data experts.

.join() question

drs
why does
''.join(lst)
not automatically do
''.join([str(i) for i in lst])


? That is, is there ever a time when one does not want .join to make
everything into a string? This seems like reasonable default behavior, but
maybe I'm missing something?

-doug
Jul 18 '05 #1
3 2907

"drs" <dr*@ecp.cc> wrote in message
news:eo********************@newssrv26.news.prodigy .com...
why does
''.join(lst)
not automatically do
''.join([str(i) for i in lst])

? That is, is there ever a time when one does not want .join to

make everything into a string? This seems like reasonable default behavior, but maybe I'm missing something?


If the members of lst are already str strings, this would be a waste
of time. If they are unicode strings, this would be the wrong thing
to do. Auto conversions are not Python's style.

Terry J. Reedy
Jul 18 '05 #2
I would risk a guess that this comes under the "explicit is better than
implicit" guideline.

''.join([str(i) for i in lst])

Explains to everyone that you know the list has some non-string things,
and you intend them to be str()'ified.

Intention-guessingly yours,
Simon.

"drs" <dr*@ecp.cc> wrote in
news:eo********************@newssrv26.news.prodigy .com:
why does
''.join(lst)
not automatically do
''.join([str(i) for i in lst])


? That is, is there ever a time when one does not want .join to make
everything into a string? This seems like reasonable default
behavior, but maybe I'm missing something?

-doug


Jul 18 '05 #3
drs
"Terry Reedy" <tj*****@udel.edu> wrote in message
news:Q4********************@comcast.com...

"drs" <dr*@ecp.cc> wrote in message
news:eo********************@newssrv26.news.prodigy .com...
why does
>> ''.join(lst)


not automatically do
>> ''.join([str(i) for i in lst])


? That is, is there ever a time when one does not want .join to

make
everything into a string? This seems like reasonable default

behavior, but
maybe I'm missing something?


If the members of lst are already str strings, this would be a waste
of time. If they are unicode strings, this would be the wrong thing
to do. Auto conversions are not Python's style.

l = [u'abcde', 'fghij']
''.join(l)

u'abcdefghij'

this seems to be auto converting the non-unicode to unicode?

-d
Jul 18 '05 #4

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

Similar topics

46
by: Leo Breebaart | last post by:
I've tried Googling for this, but practically all discussions on str.join() focus on the yuck-ugly-shouldn't-it-be-a-list-method? issue, which is not my problem/question at all. What I can't...
0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
1
by: Paul Bramscher | last post by:
Here's one for pathological SQL programmers. I've got a table of things called elements. They're components, sort of like amino acids, which come together to form complex web pages -- as nodes...
4
by: eXavier | last post by:
Hello, I have query joining several tables, the last table is joined with LEFT JOIN. The last table has more then million rows and execution plan shows table scan on it. I have indexed columns...
8
by: kieran | last post by:
Hi, I have the following sql statement. I originally had the statement with two INNER JOINS but in some situations was getting an error so changed the last INNER JOIN to a LEFT OUTER JOIN (as...
3
by: Jack Smith | last post by:
Hello, I want to be able to view data from 3 tables using the JOIN statement, but I'm not sure of how to do it. I think i don't know the syntax of the joins.I imagine this is easy for the...
3
by: Ian Boyd | last post by:
i know nothing about DB2, but i'm sure this must be possible. i'm trying to get a client to create a view (which it turns out is called a "Logical" in DB2). The query needs a LEFT OUTER JOIN, but...
7
by: germanshorthairpointer | last post by:
Hello, I'm trying to do a join based on the following tables: Person(person_id,person_name) Grade(grade_id,grade_person_id,grade_score) The data looks like this: Person:
27
by: Paulo da Silva | last post by:
Hi! I was told in this NG that string is obsolet. I should use str methods. So, how do I join a list of strings delimited by a given char, let's say ','? Old way:
12
by: Chamnap | last post by:
Hello, everyone I have one question about the standard join and inner join, which one is faster and more reliable? Can you recommend me to use? Please, explain me... Thanks Chamnap
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.