且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Python doc问题示例:gzip模块

更新时间:2023-02-17 12:20:29

今天我需要使用Python来压缩/解压缩gzip文件。


我很快找到官方文档:
http://python.org/doc/2.4.1/ lib / module-gzip.html


我想它是一个像

GzipFile(filePath,comprress / decompress,输出路径)


然而,在20秒后扫描文档没有单一的例子

显示它是如何使用的。
>
相反,该文档首先提供了一些关于与

一些zlib模块和其他软件兼容的神秘信息。


然后它在一个非常谈论关于写作不好的大电脑science方式

主要功能GzipFile。没有关于使用它的任何观点

来解决问题,也没有具体描述它是如何运作的。

相反,类,构造函数,对象等的术语被抛在了一起。 />
假定读者对Python文件对象的专业知识和

gzip技术细节。


后不理解,并且不是Python专家,我想阅读

关于文件对象但是没有链接。


找到文件对象doc page
http://python.org /doc/2.4.1/lib/bltin-file-objects.html

本身以一种模糊不清的方式进行谈话。


- -------------

这里是GzipFile描述的详细信息:


class GzipFile([filename [ ,mode [,compresslevel [,fileobj]]]])

GzipFile类的构造函数,模拟大多数方法都是一个文件对象的
,除了readinto()和truncate()

方法。至少有一个fileobj和filename必须给出一个

非平凡值。

新的类实例基于fileobj,可以是常规的

文件,StringIO对象或模拟文件的任何其他对象。它

默认为None,在这种情况下打开文件名以提供一个文件

对象。


是啊,blab blab blab 。他妈的你在说什么?那么,如何使用它?
使用它?


当fileobj不是None时,filename参数仅用于包含

在gzip文件头中,其中可能包含未压缩文件的原始

文件名。它默认为文件名

fileobj,如果可辨别的话;否则,它默认为空字符串,

,在这种情况下,原始文件名不包含在标题中。


他妈的是什么?


模式参数可以是r,rb,a,ab,w或 wb'',

取决于是读取还是写入文件。如果可辨别,则默认为

fileobj的模式;否则,默认为''rb''。如果没有给出
,那么'b''标志将被添加到模式中以确保文件是以二进制模式打开的
,以实现跨平台的可移植性。 />

可辨别?那么,他妈的究竟是这些模式呢?你不能

具体描述它们吗?


compresslevel参数是1到9之间的一个整数,用于控制

级别压缩; 1是最快的并产生最小的压缩,

和9是最慢的并产生最大的压缩。默认值为9.


调用GzipFile对象的close()方法不会关闭fileobj,

因为您可能希望在追加更多资料之后压缩数据。

这也允许你传递一个为写入而打开的StringIO对象作为

fileobj,并使用StringIO检索生成的内存缓冲区

object'的getvalue()方法。


呵呵?追加更多材料?传递一个StringIO?和内存缓冲区?


--------------------

母亲90%的程序员使用这个模块真的只想

压缩或解压缩文件。


他妈的unix拥护者和他妈的Perlers和他妈的Python蠢货。
>
PS有关Python文档的更多信息,请参阅:
http://xahlee.org/perl-python/re-write_notes.html

Xah
xa*@xahlee.org

a ?? http://xahlee.org/


Xah Lee schrieb:
今天我需要使用Python解压缩gzip文件。

因为我熟悉Python doc并且有10年的历史在unix admin和perl中有4年的计算经验,我已经快速找到官方文档:

http://python.org/doc/2.4.1/lib/module-gzip.html
他妈的Python编程蠢货。


我只需要解压缩文件。是吗:

导入gzip;
gzip.GzipFile(&Users/xah/access_log.1.gz");

可以有人举个例子吗进入那个他妈的文档,以便人们不必通过任何他妈的试图听起来很大?




这是一个例子:

导入gzip


#read fucked

fuckedfile = gzip.GzipFile(''somefile.gz'')

content = fuckedfile.read()

fuckedfile.close()


#wack unfucked

unfuckedfile = file(''somefile'',''w'')

unfuckedfile.write(content)

unfuckedfile.close()


请随意将这个他妈的例子插入到他妈的文档中。


有一个不错的...呃他妈的一天:)


-

-------------------------------------- -----------------------------

Peter Maas,M + R Infosysteme,D-52070 Aachen,电话+ 49-241-93878-0

电子邮件'cGV0ZXIubWFhc0BtcGx1c3IuZGU = \ n''。decode(''base64'')

------------------------- ------------------------------------------


Peter Maas写道:
请随意将这个他妈的例子插入到他妈的文档中。




或使用他妈的搜索引擎。搜索python< module>例如

并点击我感到很幸运。按钮往往工作得很好。例如

http: //www.google.com/search?q=pytho...+example&btnI=

< / F>


today i need to use Python to decompress gzip files.

since i''m familiar with Python doc and have 10 years of computing
experience with 4 years in unix admin and perl, i have quickly located
the official doc:

http://python.org/doc/2.4.1/lib/module-gzip.html

but after a minute of scanning, please someone tell me what the fuck is
it talking about?

Fuck the Python programing morons.

Thanks.

I just need to decompress files. Is it:

import gzip;
gzip.GzipFile("/Users/xah/access_log.1.gz");

can someone put a example into that fucking doc so that people don''t
have to wade thru whatever fuck it is trying to sound big?

For more about Python doc, please see:
http://xahlee.org/perl-python/re-write_notes.html

Xah
xa*@xahlee.org
a?? http://xahlee.org/

Today i need to use Python to compress/decompress gzip files.

I quickly found the official doc:
http://python.org/doc/2.4.1/lib/module-gzip.html

I''d imagine it being a function something like
GzipFile(filePath, comprress/decompress, outputPath)

however, scanning the doc after 20 seconds there''s no single example
showing how it is used.

Instead, the doc starts with some arcane info about compatibility with
some zlib module and other software.

Then it talks in a very big computer sciency way with bad writing about
the main function GzipFile. No perspectives whatsoever about using it
to solve a problem nor a concrete description of how it functions.
Instead, jargons of Class, Constructor, Object etc are thrown together
with presumption of reader''s expertise of Python''s file objects and
gzip technical details.

after no understanding, and being not a Python expert, i wanted to read
about file objects but there''s no link.

after locating the file object doc page
http://python.org/doc/2.4.1/lib/bltin-file-objects.html
itself talks in some obfuscated incomprehensible way.

---------------
Here''s the detail of the GzipFile description:

class GzipFile( [filename[, mode[, compresslevel[, fileobj]]]])
Constructor for the GzipFile class, which simulates most of the methods
of a file object, with the exception of the readinto() and truncate()
methods. At least one of fileobj and filename must be given a
non-trivial value.
The new class instance is based on fileobj, which can be a regular
file, a StringIO object, or any other object which simulates a file. It
defaults to None, in which case filename is opened to provide a file
object.

yeah, blab blab blab. what the fuck are you talking about? So, how to
use it?

When fileobj is not None, the filename argument is only used to be
included in the gzip file header, which may includes the original
filename of the uncompressed file. It defaults to the filename of
fileobj, if discernible; otherwise, it defaults to the empty string,
and in this case the original filename is not included in the header.

what the fuck??

The mode argument can be any of ''r'', ''rb'', ''a'', ''ab'', ''w'', or ''wb'',
depending on whether the file will be read or written. The default is
the mode of fileobj if discernible; otherwise, the default is ''rb''. If
not given, the ''b'' flag will be added to the mode to ensure the file is
opened in binary mode for cross-platform portability.

discernible? so, what the fuck are exactly these modes? can''t you
describe them concretely?

The compresslevel argument is an integer from 1 to 9 controlling the
level of compression; 1 is fastest and produces the least compression,
and 9 is slowest and produces the most compression. The default is 9.

Calling a GzipFile object''s close() method does not close fileobj,
since you might wish to append more material after the compressed data.
This also allows you to pass a StringIO object opened for writing as
fileobj, and retrieve the resulting memory buffer using the StringIO
object''s getvalue() method.

huh? append more material? pass a StringIO? and memory buffer?

--------------------
Motherfucking 90% of programers using this module really just want to
compress or decompress a file.

Fuck unix advocates and fuck Perlers and fuck Python morons.

PS For more about Python doc, please see:
http://xahlee.org/perl-python/re-write_notes.html

Xah
xa*@xahlee.org
a?? http://xahlee.org/


Xah Lee schrieb:
today i need to use Python to decompress gzip files.

since i''m familiar with Python doc and have 10 years of computing
experience with 4 years in unix admin and perl, i have quickly located
the official doc:

http://python.org/doc/2.4.1/lib/module-gzip.html

but after a minute of scanning, please someone tell me what the fuck is
it talking about?

Fuck the Python programing morons.

Thanks.

I just need to decompress files. Is it:

import gzip;
gzip.GzipFile("/Users/xah/access_log.1.gz");

can someone put a example into that fucking doc so that people don''t
have to wade thru whatever fuck it is trying to sound big?



Here''s the example:
import gzip

# read fucked
fuckedfile = gzip.GzipFile(''somefile.gz'')
content = fuckedfile.read()
fuckedfile.close()

# write unfucked
unfuckedfile = file(''somefile'',''w'')
unfuckedfile.write(content)
unfuckedfile.close()

Please feel free to insert this fucking example into the fucking docs.

Have a nice ... eh fucking day :)

--
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0
E-mail ''cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n''.decode(''base64'')
-------------------------------------------------------------------


Peter Maas wrote:
Please feel free to insert this fucking example into the fucking docs.



or use the fucking search engine. searching for "python <module> example"
and clicking the "I feel lucky" button tends to work quite well. e.g.

http://www.google.com/search?q=pytho...+example&btnI=

</F>