Mihai Iacob wrote:

>Hello
>
>
>def saveBugs(data):
>    store = open(filename, 'w')
>    for timeMark,aList in data.items():
>        store.write(timeMark + '\n')
>        store.write(aList + '\n')
>    store.close()
>
>data is a dictionary
>aList is a list
>
>After i run this part the following error pops up:
>
>Traceback (most recent call last):
>  File "C:\Python\Bugs.py", line 133, in <module>
>    main()
>  File "C:\Python\Bugs.py", line 130, in main
>    saveBugs(dataBugs)
>  File "C:\Python\Bugs.py", line 17, in saveBugs
>    store.write(aList + '\n')
>TypeError: can only concatenate list (not "str") to
>list
>
>Can anybody tell me how to make it work
>
>
> 
>____________________________________________________________________________________
>Yahoo! Music Unlimited
>Access over 1 million songs.
>http://music.yahoo.com/unlimited
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>  
>
Hi Mihai,
The error says it all. You cant concatenate a string to a list 
[1,2,3,4,5] + '\n',
Try [1,2,3,4,5] + '\n' in the interpretor, you ll get the same error.
write() doesn't know what to do with a list as [i think] it will only 
handle strings.
If you wrap your list in str() for writing, that should do the trick

Wouldn't hurt to wrap timeMark in str() also, unless your positive that 
the keys will always be strings

        store.write(str(timeMark) + '\n')
        store.write(str(aList) + '\n')


HTH
Good Luck,
Glenn

-- 
"Ketchup. For the good times... " - Ketchup Advisory Board 
Glenn Norton
Application Developer
Nebraska.gov
1-402-471-2777
[EMAIL PROTECTED]

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to