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

Saran A ahlusar.ahluwalia at gmail.com
Thu Apr 2 14:02:55 CEST 2015


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"


The sample code that I am trying to run is:

path = "/Users/Desktop/Projects/"
dirlist = os.listdir(path)
before = dict([(f, None) for f in os.listdir(dirlist)])

def main(dirlist):
    while True:
        time.sleep(10) #time between update check
    after = dict([(f, None) for f in os.listdir(dirlist)])
    added = [f for f in after if not f in before]
    if added:
        print('Successfully added new file - ready to validate')
if __name__ == "__main__": 
    main() 







More information about the Python-list mailing list