473,729 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python doc problems example: gzip module

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
∑ http://xahlee.org/

Aug 31 '05 #1
10 3913
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(filePa th, 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 incomprehensibl e 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
∑ http://xahlee.org/

Aug 31 '05 #2
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.clos e()

# write unfucked
unfuckedfile = file('somefile' ,'w')
unfuckedfile.wr ite(content)
unfuckedfile.cl ose()

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 'cGV0ZXIubWFhc0 BtcGx1c3IuZGU=\ n'.decode('base 64')
-------------------------------------------------------------------
Aug 31 '05 #3
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>

Aug 31 '05 #4
Xah Lee enlightened us with:
but after a minute of scanning, please someone tell me what the fuck
is it talking about?


How difficult is it? The first line of the Gzip class explains it all
to me: "Constructo r for the GzipFile class, which simulates most of
the methods of a file object"

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Aug 31 '05 #5
nothing personal my friend. But just in case you are interested about
getting it:

the question here is about quality of documentation, not about whether
you got it.
http://xahlee.org/UnixResource_dir/writ/python_doc.html

Xah
xa*@xahlee.org
∑ http://xahlee.org/
Sybren Stuvel wrote:
Xah Lee enlightened us with:
but after a minute of scanning, please someone tell me what the fuck
is it talking about?


How difficult is it? The first line of the Gzip class explains it all
to me: "Constructo r for the GzipFile class, which simulates most of
the methods of a file object"


Sep 1 '05 #6
>> Constructor for the GzipFile class, which simulates most of the methods
of a file object, with the exception of the readinto() and truncate()
yeah, blab blab blab. what the fuck are you talking about? So, how to
use it?


um... presumably you type "zippedfile = GzipFile(...)" and depending on
whether you are creating a new file, or extracting an existing
GzipFile. the documentation says:
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."
so i guess in your case you would want to do "zippedfile =
GzipFile("myfil e.gz")".
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??


when you "gzip -d myfile.gz", the resultant output name might not be
"myfile". The uncompressed name can be stored in the gzip header, and
so if you provide both a fileobj argument and a filename argument to
the GzipFile constructor, it will use fileobj for the data stream and
just place filename into the header (as opposed to opening the file
"filename") .
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?


these are the same modes that are used in just about every single
programming language when it comes to opening files. these modes are
described in the Python tutorial and in the core Python documentation
about files and file I/O. It should not be surprising, therefore, that
GzipFile, which "simulates most of the methods of a file object",
should have the same semantics when it comes to file modes.

it is actually quite shocking to me that someone with 10 years of
computing experience would not know what "rb" and "rb" mean in the
context of opening files in a programming language.
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?


you see, not everyone who uses GzipFile will be decompressing files.
sometimes they will be *compressing* file data. in this case, it's
very possible that they want to compress data going over a network
stream, or embed some gzipped into the middle of their own file format.
GzipFile doesn't make any assumptions about what the user is going to
do with the gzipped data or the file object that the Gzip module is
writing into/reading from.
Motherfucking 90% of programers using this module really just want to
compress or decompress a file.


I disagree. I think a whopping (non-motherfucking) 100% of programmers
using this module want to compress or decompress file data. If someone
just wants to decompress a file, wouldn't they just do:

import os
os.system("gzip -d filename.gz")

The GzipFile module is meant to be used by folks who want to gzip or
gunzip file data in a programmatic function. It's not meant to be a
drop-in, shell-scripting replacement for the gzip command.

-peter

Sep 1 '05 #7
On 1 Sep 2005 07:24:26 -0700
Peter Wang wrote:
Constructor for the GzipFile class, which simulates most of the methods
of a file object, with the exception of the readinto() and truncate()


yeah, blab blab blab. what the fuck are you talking about? So, how to
use it?
and in this case the original filename is not included in the header.


what the fuck??

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?


you see, not everyone who uses GzipFile will be decompressing files.


Am I the only one who thinks you are talking with some perverted kind of
emacs-doctor-like or elise-like computer program?

--
jk
Sep 1 '05 #8

Peter Maas wrote:
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.clos e()

# write unfucked
unfuckedfile = file('somefile' ,'w')
unfuckedfile.wr ite(content)
unfuckedfile.cl ose()

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 'cGV0ZXIubWFhc0 BtcGx1c3IuZGU=\ n'.decode('base 64')
-------------------------------------------------------------------


yes yes yes, i love this "fucking" post...nice "fucking" response
man!!!!

Sep 1 '05 #9

Peter Maas wrote:
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.clos e()

# write unfucked
unfuckedfile = file('somefile' ,'w')
unfuckedfile.wr ite(content)
unfuckedfile.cl ose()

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 'cGV0ZXIubWFhc0 BtcGx1c3IuZGU=\ n'.decode('base 64')
-------------------------------------------------------------------


The word has now completely lost any meaning for me.

Sep 2 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2645
by: Matthew Thorley | last post by:
Is there a module for unpacking tar files in python? how about bzip2 and gzips? I know I can use the gzip module for gzips but is there anything that can detect what format a file is in and decopress and unpack it using the other methods? thanks -Matthew
25
7749
by: Xah Lee | last post by:
Python Doc Problem Example: gzip Xah Lee, 20050831 Today i need to use Python to compress/decompress gzip files. Since i've read the official Python tutorial 8 months ago, have spent 30 minutes with Python 3 times a week since, have 14 years of computing experience, 8 years in mathematical computing and 4 years in unix admin and perl, i have quickly found the official doc: http://python.org/doc/2.4.1/lib/module-gzip.html
14
7138
by: Bill | last post by:
I've written a small program that, in part, reads in a file and parses it. Sometimes, the file is gzipped. The code that I use to get the file object is like so: if filename.endswith(".gz"): file = GzipFile(filename) else: file = open(filename) Then I parse the contents of the file in the usual way (for line in
0
361
by: Kurt B. Kaiser | last post by:
Patch / Bug Summary ___________________ Patches : 378 open ( +3) / 3298 closed (+34) / 3676 total (+37) Bugs : 886 open (-24) / 5926 closed (+75) / 6812 total (+51) RFE : 224 open ( +7) / 227 closed ( +7) / 451 total (+14) New / Reopened Patches ______________________
3
2734
by: Joost | last post by:
Hi guys, I have couple of simple python based active server pages that make use of httplib2 which uses gzip.py. IIS, however, also has a gzip.dll located at the iis/inetsrv path. When using ASP the iis/inetsrv path is placed as the first item in sys.path. Consequently importing httplib2 will cause the following error: import httplib2 File "c:\python24\lib\site-packages\httplib2-0.2.0-py2.4.egg
1
11110
by: John Nagle | last post by:
I have a large (gigabytes) file which is encoded in UTF-8 and then compressed with gzip. I'd like to read it with the "gzip" module and "utf8" decoding. The obvious approach is fd = gzip.open(fname, 'rb',encoding='utf8') But "gzip.open" doesn't support an "encoding" parameter. (It probably should, for consistency.) Is there some way to do this? Is it possible to express "unzip, then decode utf8" via "codecs.open"?
4
3958
by: Aidan | last post by:
Hi, I'm having a bit of trouble with a python script I wrote, though I'm not sure if it's related directly to python, or one of the other software packages... The situation is that I'm trying to create a system backup script that creates an image of the system, filters the output though gzip, and then uploads the data (via ftp) to a remote site.
0
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.