[Tutor] New to Programming: TypeError: coercing to Unicode: need string or buffer, list found

Danny Yoo danny.yoo at gmail.com
Thu Apr 2 19:45:14 CEST 2015


On Apr 2, 2015 9:45 AM, "Saran Ahluwalia" <ahlusar.ahluwalia at gmail.com>
wrote:
>
> Good Morning:
>
> I understand this error message when I run this code. However, I am
curious
> to know what the most pythonic way is to convert  the list to a string? I
> use Python 2.7.
>
> "Traceback (most recent call last):
> before = dict([(f, None) for f in os.listdir(dirlist)])
> TypeError: coercing to Unicode: need string or buffer, list found"

I actually do not understand the error.  :p

In particular, I do not understand the subexpression:

    os.listdir(dirlist)

Can you explain what you are trying to do there?  The listdir function only
consumes single strings, so this looks like a mistake unless dirlist is a
string.


More information about the Tutor mailing list