fileobj.write(buffer(...))
Alexander Semenov
sav at ulmen.mv.ru
Thu Feb 22 13:42:02 EST 2001
"Tomasz Lisowski" <lisowski.tomasz at sssa.NOSPAM.com.pl> wrote in message
news:972ip3$juj$1 at news.tpi.pl...
> Uzytkownik "Niki Spahiev" <spahievi at vega.bg> napisal w wiadomosci
> news:mailman.982795168.21257.python-list at python.org...
> > Is this working as expected?
> > >>> open( 'test', 'w' ).write( buffer( 'abcd', 2 ) )
> > >>> from cStringIO import StringIO
> > >>> StringIO().write( buffer( 'abcd', 2 ) )
> > Traceback (innermost last):
> > File "<pyshell#4>", line 1, in ?
> > StringIO().write( buffer( 'abcd', 2 ) )
> > SystemError: bad argument to internal function
> What about closing the file? Since you do not have a reference to the file
> object, you are not able to close it. Perhaps it would be better to write:
No, python python implements reference counting. Then file object loose all
references it will del-ed. I think file object handles del correctly and
closes
corresponding handle.
> Don't know about StringIO, sorry :-(
As for StringIO, my "Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit
(Intel)] on win32"
is more informatical: it says:
>>> from cStringIO import StringIO
>>> StringIO().write( buffer( 'abcd', 2 ) )
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: expected string or Unicode object, buffer found
It looks like StringIO have some limitation in supporting buffers.
WBR,
Alexander Semenov
More information about the Python-list
mailing list