473,757 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

handling tar, gz and bz2 with python

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
Jul 19 '05 #1
1 2647
Matthew Thorley wrote:
Is there a module for unpacking tar files in python?
import tarfile
help(tarfile)

...
| open(cls, name=None, mode='r', fileobj=None, bufsize=10240) from __built
in__.type
| Open a tar archive for reading, writing or appending. Return
| an appropriate TarFile class.
|
| mode:
| 'r' open for reading with transparent compression
| 'r:' open for reading exclusively uncompressed
| 'r:gz' open for reading with gzip compression
| 'r:bz2' open for reading with bzip2 compression
| 'a' or 'a:' open for appending
| 'w' or 'w:' open for writing without compression
| 'w:gz' open for writing with gzip compression
| 'w:bz2' open for writing with bzip2 compression
| 'r|' open an uncompressed stream of tar blocks for reading
| 'r|gz' open a gzip compressed stream of tar blocks
| 'r|bz2' open a bzip2 compressed stream of tar blocks
| 'w|' open an uncompressed stream for writing
| 'w|gz' open a gzip compressed stream for writing
| 'w|bz2' open a bzip2 compressed stream for writing
|
| taropen(cls, name, mode='r', fileobj=None) from __builtin__.typ e
| Open uncompressed tar archive name for reading or writing.
...
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?


see above.

</F>

Jul 19 '05 #2

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

Similar topics

1
1431
by: Dan Williams | last post by:
Hi people Part of the reason I have started using Python (experience: 3 days) is that I recognise the potential benefits in using it compared to writing C/C++ code. In particular, there are a couple of modules in an application that I am writing that I have calculated will be up to ten times quicker to develop (although it is hard to say at this stage), which is obviously quite attractive. The "problem" I have is relating to the...
3
7147
by: alastair | last post by:
Hi, I am trying to use Python to do the following: - read in an image in geoTIFF format - extract the tags from the file - do something interesting with the tags I've read about the Python Imaging Library (PIL) which seems to do what I need with TIFF files. I was wondering if anyone knows if this
9
3204
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is indeed also true for our language of choice, Python. Its file type allows some extraordinary convenient access like: for line in open("blah"): handle_line(line)
11
2863
by: Josh | last post by:
Hi, I am having a problem with Python. I am new to Python as a programming language, but I do have experience in other languages. I am experiencing strange problems with File handling and wonder if anyone else has seen this or knows what I am doing wrong. I am simply trying to open a file for read and iterate through until the end of file. I am able to do so without a problem, but here's the catch: The open statement is only working on...
3
1916
by: Gonçalo Rodrigues | last post by:
Hi all, I've got two somewhat general questions related to exception handling in C++. My usual programming language is the lovely and flexible Python, but for various reasons, including the need to interface with third-party libraries, get extra performance, etc. I have to use C++. Now in Python, being a dynamically typed language, everything is pushed to the run-time. Additionaly, since the language does not guarantee deterministic...
22
4424
by: Andy McDonagh | last post by:
Dear python experts, I am new to python and this site, so I apologize if this is off topic (i.e. is it a SciPy question?). I will try to demonstrate my problem below: -------------------------------------------------------- #!/usr/local/bin/python from scipy import * from scipy.stats import * a=norm(loc=0,scale=1) a_data = a.rvs(10)
2
2988
by: Petr Jakes | last post by:
I am a little bit confused by all possibilities for exceptions handling in Python (probably because I am not skilled enough??) I did try to search trough this list and reading Python tutorial about Errors and Exceptions but didn't find some "general" answer about exception handling policy (strategy). In the following example each row can IMHO raise an exception (if the Firebird service is not running for example, if the database is...
8
2031
by: Adil Akram | last post by:
There are situations where you want to retry/rerun the same code again (if user wants) for unlimited times for a particular exception thrown. For example in situations like there's no CD in the drive or some file is locked by another process you want to display message dialog to user with "Retry" and "Cancel" buttons (As Windows shows "Retry" option if no CD in drive) and if user clicks "Retry" you want to run the same code again that...
17
8485
by: frederic.pica | last post by:
Greets, I've some troubles getting my memory freed by python, how can I force it to release the memory ? I've tried del and gc.collect() with no success. Here is a code sample, parsing an XML file under linux python 2.4 (same problem with windows 2.5, tried with the first example) : #Python interpreter memory usage : 1.1 Mb private, 1.4 Mb shared #Using http://www.pixelbeat.org/scripts/ps_mem.py to get memory information
35
3508
by: eliben | last post by:
Python provides a quite good and feature-complete exception handling mechanism for its programmers. This is good. But exceptions, like any complex construct, are difficult to use correctly, especially as programs get large. Most of the issues of exceptions are not specific to Python, but I sometimes feel that Python makes them more acute because of the free-n- easy manner in which it employs exceptions for its own uses and allows users...
0
9487
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
9297
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
10069
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
9904
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
9884
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
6556
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5168
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...
1
3828
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.