[Tutor] Create file / Print list to file

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Aug 12 01:36:35 CEST 2004



On Thu, 12 Aug 2004, Klas Marteleur wrote:

>   File "/home/klas/Python_filer/Tragic/CreateEbomFromFile4.py", line 80, in
> writeListToFile
>     lineData = ' '.join(line)
> TypeError: sequence item 10: expected string, int found


Hi Klas,

The join() method requires that every element in the 'line' should be a
string.  It's a function that takes a sequence of strings, and returns a
string.

But many of your example data lines have numbers.  For example:

    ['03003365', ';', 'AB', ';', '03003359', ';', 'AB', ';', '8', ';',
     80, ';', '8', ';', '-', ';', '', ';', '-', ';', 'YES']
     ^^

has the number 80 in there.


You can probably do something like:

     lineData = ' '.join([str(x) for x in line])

to first pass each element through the str() conversion function, and then
join those strings together.


Hope this helps!



More information about the Tutor mailing list