Get the entire file in a variable - error

Jeff Epler jepler at unpythonic.net
Thu Apr 14 10:57:40 EDT 2005


It's not clear to me what you mean by "the first line" (gzip does not
output a file composed of lines, its output is byte-oriented).

Printing tst.getvalue() is probably not a very useful thing to do, since
it won't do anything useful when the output is a terminal, and it will
add an extra newline if you are redirecting to a file.

At least when close()ing the GzipFile before looking at the StringIO
instance's value, I get some bytes that gunzip just fine, giving the
original string.

Here's my interactive session:
>>> import gzip
>>> import StringIO
>>> io = StringIO.StringIO()
>>> z = gzip.GzipFile("test.gz", "w", 5, io)
>>> z.write("""\
... Python 2.2.2 (#1, Feb 24 2003, 19:13:11) 
... [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
... Type "help", "copyright", "credits" or "license" for more information.
... """)
>>> z.close()
>>> from os import popen
>>> popen("gunzip -dc", "w").write(io.getvalue())
Python 2.2.2 (#1, Feb 24 2003, 19:13:11) 
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

I don't know anything about your database or its "LONG field".
Depending on the database software there could be additional problems
with embedded NULs, for instance.

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050414/2ded2204/attachment.sig>


More information about the Python-list mailing list