haven't looked at the code - but the above is a good sign
iterating over a string object not a list object.
try this and you'll see:
for item in foo:
do a type() on the object you're getting the output from above and I bet
it's as string not a list.
Good call, that fixed it :).