join vs instances

Robin Becker robin at jessikat.fsnet.co.uk
Mon Dec 10 06:14:08 EST 2001


In article <3C13F9D7.5091357 at earthlink.net>, Hans Nowak
<wurmy at earthlink.net> writes
>I haven't looked at the C code, but I expect that it wants the types
>of the list items to be <type "string">, not "something that behaves
>like a string". The latter can often be done in Python code, but I
>guess this wasn't an option for built-in (C) functions.
> 
>There are other examples of this in Python, for 
>example exec, that takes a dictionary but not a UserDict:
>
>>>> from UserDict import UserDict
>>>> d = UserDict()
>>>> exec 'print "Hello"' in d
>Traceback (most recent call last):
>  File "<pyshell#2>", line 1, in ?
>    exec 'print "Hello"' in d
>TypeError: exec: arg 2 must be a dictionary or None
>
>There are several workarounds possible, e.g. doing a map(str, lst)
>where lst is your list that contains UserString instances, then
>joining it.
>
>--Hans
the map(str,lst) would be the easiest. It's strange, but I thought
Python would allow some kind of coercion pretty well every where. 
-- 
Robin Becker



More information about the Python-list mailing list