get-a-cup-of-coffee slow (fwd)

Alex Martelli aleaxit at
Fri Aug 10 10:18:52 CEST 2001

"Mark Rowe" <mark21rowe at> wrote in message
news:3b737128 at
> Hi,
> The first example should be written:
> >>> l=[0,1,2,3,4]
> >>> f=open('e', 'w')
> >>> f.write(''.join(l))
> and the second should  be something like:
> >>> l=[0,1,2,3,4]
> >>> f=open('e', 'w')
> >>> l2 = map(str, l)
> >>> f.writelines(l2)
> This is because f.write() takes a expects a string argument, not a list,
> f.writelines() expects a list of strings, not a list of integers.

Yes, but remember the original question, which you quote below:

> presumably more
> > > >|suited to being appended), but then I realized that I didn't know
> to write
> > > >|the contents of a list to a file as a stream of bytes.  There's

"a stream of bytes" suggests that the posted wanted to use chr, not
str, as the function to be mapped.  Anyway, array.array has far better
performance for this task.


More information about the Python-list mailing list