marshal doesn't work with "file-like" objects

echuck at mindspring.com echuck at mindspring.com
Fri Jan 26 18:30:58 EST 2001


In article <mailman.980540325.4462.python-list at python.org>,
  "Tim Peters" <tim.one at home.com> wrote:
> [Chuck Esterbrook]
> >  >>> from StringIO import StringIO
> >  >>> f = StringIO()
> >  >>> f.write('hi')
> >  >>> import marshal
> >  >>> marshal.dump(1, f)
> > Traceback (most recent call last):
> >    File "<stdin>", line 1, in ?
> > TypeError: marshal.dump() 2nd arg must be file
> >
> > So is that a bug, a flaw or a feature?
>
> It's functioning as documented (read the docs), and is also
functioning as
> designed (read next sentence), so it's not a bug.  As the docs say,
marshal
> is primarily intended for Python's own use in reading and
writing .pyc and
> .pyo files, and, as the docs don't say, to make it as fast as
possible for
> those purposes it doesn't support any luxuries.  So it's a feature
from
> Python's POV, but a flaw from yours.  Python wins <0.9 wink>.
>
> You could do this instead:
>
>     filelikeobject.write(marshal.dumps(object))
>
> Reading a sequence of marshaled values back from a file-like object
is more
> of a puzzle!

Does anyone really believe that there is any difference in performance?
Supporting file-like objects would add the overhead of a message pass.
But what's taking place here is file I/O that easily ranges from 1K to
40K (according to my dir *.pyc).

I seriously doubt that if message passing were suddenly employed [a]
anyone would notice and [b] any Python benchmarks would change.

I win <0.95 wink>.


-Chuck


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list