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

Grant Griffin not.this at seebelow.org
Thu Aug 9 23:08:57 EDT 2001


Quinn Dunkan wrote:
> 
> On Thu, 09 Aug 2001 18:12:31 -0400, Lulu of the Lotus-Eaters <mertz at gnosis.cx>
> wrote:
> >Grant Griffin wrote:
> >|Also, I tried writing something like this with a list (which are presumably more
> >|suited to being appended), but then I realized that I didn't know how to write
> >|the contents of a list to a file as a stream of bytes.  There's probably a
> >|simple way to do that: what is it?
> >
> >''.join(lst)         # Python 2.0+
> >string.join(lst,'')  # Python 1.4+ (or something)
> 
> There is also file.writelines(lst).  It's not documented in my version of
> python, so maybe you're not supposed to use it, but why put it there then?
> It's been there for quite a while now.

The other day I had tried that with "write".  It went something like
this:

   Python 2.0.1 (#18, Jun 30 2001, 10:36:44) [MSC 32 bit (Intel)] on
win32
   Type "copyright", "credits" or "license" for more information.
   >>> l=[0,1,2,3,4]
   >>> f=open('e', 'w')
   >>> f.write(l)
   Traceback (most recent call last):
     File "<stdin>", line 1, in ?
   TypeError: read-only character buffer, list

but maybe it should have been "writelines" instead:

   >>> f.writelines(l)
   Traceback (most recent call last):
     File "<stdin>", line 1, in ?
   TypeError: writelines() requires sequences of strings
   >>>

what-part-of-'Traceback'-don't-I-understand?-<wink>-ly y'rs,

=g2
-- 
_____________________________________________________________________

Grant R. Griffin                                       g2 at dspguru.com
Publisher of dspGuru                           http://www.dspguru.com
Iowegian International Corporation            http://www.iowegian.com



More information about the Python-list mailing list