<p>I have been bitten by something unexpected recently. I wanted to make something like that:</p>

<pre><code>try :
     thing.merge(iterable) # this is an iterable so I add it to the list
except TypeError :
     thing.append(iterable) # this is not iterable, so I add it
</code></pre>

<p>Well, It was working fine until I passed an object inheriting from Exception which was supposed to be added.</p>

<p>Unfortunetly, an Exception is iterable. The following code does not raise any <code>TypeError</code>:</p>

<pre><code>for x in Exception() :
    print 1
</code></pre>

<p>Does anybody know why?</p>

NOT VALID. Check Brian anwser.
Ok, I just got it :
```
```
for x in Exception("test") :
    print x
   ....:     
   ....:     
test
```
```
Don't bother ;-)
Anyway, it's good to know.
EDIT : looking to the comments, I feel like adding some explanations.
An exception contains a message you passed to during instantiation :
```
```
raise Exception("test") 

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Exception: test
```
```
It's fair to say that the message is what defines the Exception the best, so str() returns it :
```
```
print Exception("test") 
test
```
```
Now, it happens that Exceptions are implicitly converted to string when used in something else than an Exception context.
So when I do :
```
```
for x in Exception("test") :
    print x
```
```
I am iterating over the string "test".
And when I do :
```
```
for x in Exception() :
    print x
```
```
I do iterate over an empty string. Tricky. Because when it comes to my issue :
```
```
try :
    thing.merge(ExceptionLikeObject)
except TypeError :
    ...
```
```
This won't raise anything since ExceptionLikeObject is considered as a string.
Well now, we know the HOW, but I still not the WHY. Maybe the built-in Exception inherit from the built-in String ? Because as far as I know :
adding
str
does not make any object iterable.
I bypassed the problem by overloding
iter
, making it raising TypeError !
Not a problem anymore, but still a mystery.