Why doesn't join() call str() on its arguments?

news.sydney.pipenetworks.com nytimes at swiftdsl.com.au
Thu Feb 17 03:07:40 EST 2005


Nick Vargish wrote:
> Leo Breebaart <leo at lspace.org> writes:
> 
> 
>>That suggests
>>to me an "obvious default" of the kind that exists elsewhere in
>>Python as well.
> 
> 
> I feel pretty much the opposite... If a non-string-type has managed to
> get into my list-of-strings, then something has gone wrong and I would
> like to know about this potential problem.
> 
> If you want to do force a conversion before the join, you can use a 
> list comp:
> 
> ', '.join([str(x) for x in l])
> 
> 
> Nick "Explicit is better than Implicit"
> 

Really ? Then why are you using python. Python or most dynamic languages 
are are so great because of their common sense towards the "implicit". 
You must have heard of "never say never" but "never say always" (as in 
"always better") is more appropriate here. There are many cases of 
python's implicitness.

What about

a = "string"
b = 2
c = "%s%s" % (a, b)

There is an implicit str(b) here.

''.join(["string", 2]) to me is no different then the example above.


Huy



More information about the Python-list mailing list