opposite of zip()?

Given a bunch of arrays, if I want to create tuples, there is zip(arrays). What if I want to do the opposite: break a tuple up and append the values to given arrays: map(append, arrays, tupl) except there is no ...

Posted On: Monday 26th of November 2012 12:07:55 AM Total Views:  253
View Complete with Replies

Related Messages:

GzipFile(fileobj=sys.stdin) Why not?   (74 Views)
Appears like a patch was submitted to allow GzipFile to work from pipes long ago. But there's no comment on why this was never accepted. Is there a good reason -Brian
Beginner Question : Iterators and zip   (51 Views)
Hi group, I have a basic question on the zip built in function. I am writing a simple text file comparison script, that compares line by line and character by character. The output is the original file, with an X in place of any characters that are different. I have managed a solution for a fixed (3) number of files, but I want a solution of any number of input files. The outline of my solution: for vec in zip(vec_list[0],vec_list[1],vec_list[2]): res = '' for entry in zip(vec[0],vec[1],vec[2]): if len(set(entry)) > 1: res = res+'X' else: res = res+entry[0] outfile.write(res) So vec is a tuple containing a line from each file, and then entry is a tuple containg a character from each line. 2 questions 1) What is the general solution. Using zip in this way looks wrong. Is there another function that does what I want 2) I am using set to remove any repeated characters. Is there a "better" way Any other comments/suggestions appreciated.
reading from a gzip file   (94 Views)
, I have a gzip file and I try to read from this file withe the next statements: gunziped_file = gzip.GzipFile('gzip-file') input_file = open(gunziped_file,'r') But I get the nezt error message: Traceback (most recent call last): File "", line 131, in input_file = open(gunziped_file,'r') TypeError: coercing to Unicode: need string or buffer, instance found I think that I do some mistake. Would some body tell me what is my mistake Nader
Problem with zipfile and newlines   (75 Views)
I'm using the zipfile library to read a zip file in Windows, and it seems to be adding too many newlines to extracted files. I've found that for extracted text-encoded files, removing all instances of '\r' in the extracted file seems to fix the problem, but I can't find an easy solution for binary files. The code I'm using is something like: from zipfile import Zipfile z = Zipfile(open('')) extractedfile ='filename_in_zippedfile') I'm using Python version 2.5. Has anyone else had this problem before, or know how to fix it
Does python support working with password protected zip files?   (72 Views)
I'm new to Python and trying to figure out how to read and write to password protected zip files. I can work with plain zip files no problem. I've googled this topic and am coming up empty except for a post on that seemed to imply that password protected zip files may( ) be supported in Python 2.6 and ads for a commercial Windows (only) zip component from Any suggestions Thank you, Malcolm
zip function for python   (87 Views)
Ive written this easy and fast function cause there it was impossible for me to find one that zip a directory without external libraries: import zipfile import sys import os def zipdir(zipPath,directory="./"): """Store the cdontent of directory to a zipPath file, if directory is not given stores the content of the current dir ( )""" directory=os.path.realpath(directory) zipObject = zipfile.ZipFile(zipPath, 'w') for root, dirs, files in os.walk(directory): for file in files: arcfile=root[len(os.path.commonprefix((directory, root))) +1:]+"/"+file #retrieves the inner relative file path filepath=os.path.join(root,file) zipObject.write(filepath,arcfile) zipObject.close() return zipObject #for optional further elaborations
pure python data compression (zip)   (86 Views)
Hallo I wonder if there are any pure python implementations available/known for the zip (or any other) data compression... As far as I know python's zlib uses, which is written in C. Unfortunately this is not solution for me, because my target "only" has a python interpreter.... I have "googled" for a while, but I don't have found anything useful.
Unable to read large files from zip   (92 Views)
I posted this on the forum, but nobody seems to know the solution: I have a zip file that is several GB in size, and one of the files inside of it is several GB in size. When it comes time to read the 5+GB file from inside the zip file, it fails with the following error: File "...\", line 491, in read bytes = OverflowError: long it too large to convert to int Note: all the other smaller files up to that point come out just fine. Here's the code: ------------------ import zipfile import re dataObj = zipfile.ZipFile("","r") for i in dataObj.namelist(): -----print i+" -- >="+str(dataObj.getinfo(i).compress_size /1024 / 1024)+"MB" -----if(i[-1] == "/"): ----------print "Directory -- won't extract" -----else: ----------fileName = re.split(r".*/",i,0)[1] ----------fileData = There have been one or more posts about 2GB limits with the zipfile module,as well as this bug report: Also, older zip formats have a 4GB limit. However, I can't say for sure what the problem is. Does anyone know if my code is wrong or if there is a problem with Python itself If Python has a bug in it, then is there any other alternative library thatI can use (It must be free source: BSD, MIT, Public Domain, Python license; not copyleft/*GPL) If not that, is there any similarly licensed code inanother language (like c++, lisp, etc...) that I can use _________________________________________________________________ Messenger Caf open for fun 24/7. Hot games, cool activities served daily. Visit now. http://cafemessenger.comocid=TXT_TAGLM_AugWLtagline
Trying to find zip codes/rest example   (95 Views)
, A couple months ago there was an example posted in a blog of a rest interface for validating zip codes. If I recall correctly, the backend validator was written in python. The validator demo page had a single text input; next to the text input would appear either a green check or a red X depending on whether the zip code was valid. On the backend, the explanation of the demo included a discussion of using HTTP status codes (200 for a valid zip, 406 for invalid) so that the service could be used from a console as well. I now cannot find this demo and the associated discussion. Does anybody remember this demo and where I might be able to find it
zip() function troubles   (80 Views)
all, I've been debugging the reason for a major slowdown in a piece of code ... and it turns out that it was the zip function. In the past the lists that were zipped were reasonably short, but once the size exceeded 10 million the zip function slowed to a crawl. Note that there was memory available to store over 100 million items. Now I know that zip () wastes lots of memory because it copies the content of the lists, I had used zip to try to trade memory for speed (heh!) , and now that everything was replaced with izip it works just fine. What was really surprising is that it works with no issues up until 1 million items, but for say 10 million it pretty much goes nuts. Does anyone know why is there some limit that it reaches, or is there something about the operating system (Vista in the case) that makes it behave like so I've noticed the same kinds of behavior when trying to create very long lists that should easily fit into memory, yet above a given threshold I get inexplicable slowdowns. Now that I think about is this something about the way lists grow when expanding them and here is the code: from itertools import izip BIGNUM = int(1E7) # let's make a large list data = range(BIGNUM) # this works fine (uses about 200 MB and 4 seconds) s = 0 for x in data: s += x print s # this works fine, 4 seconds as well s = 0 for x1, x2 in izip(data, data): s += x1 print s # this takes over 2 minutes! and uses 600 MB of memory # the memory usage slowly ticks upwards s = 0 for x1, x2 in zip(data, data): s += x1 print s , Istvan Albert writes: > I tested this on a linux server system with 4Gb of RAM > a = [ 0 ] * 10**7 > takes miliseconds, but say the > b = zip(a,a) > will take a very long time to finish: Do a top or vmstat while that is happening and see if you are swapping. You are allocating 10 million ints and 10 million tuple nodes, = 20 million objects. Although, even at 100 bytes per object that would be 1GB which would fit in your machine easily. Is it a 64 bit cpu
Re: Py2exe embed my modules to   (73 Views)
Create your py2exe distribution without a zipfile and all the modules will just be put into the installation directory. Use Inno Setup to make a proper installer for your application. -Larry On Thu, 2008-03-27 at 06:44 -0700, wrote: > ...
Re: Does python support working with password protected zip files?   (92 Views)
On 3/6/08, Malcolm Greene wrote: > I'm new to Python and trying to figure out how to read and write to > password protected zip files. > > I can work with plain zip files no problem. > > ...
simple python script to zip files   (79 Views)
I'm just starting to learn some Python basics and are not familiar with file handling. Looking for a python scrip that zips files. So aaa.xx bbb.yy ccc.xx should be zipped to I haven't been able to ...
Request for loading zipped modules in some context   (82 Views)
When trying to import a module from a filesystem directory there are several possibilities. Most obviously one can use an import statement but if this is not sufficient one has also API functions. However these API functions don't seem to ...
IOError: decoder zip not available when using PIL   (85 Views)
I keep getting the error message "IOError: decoder zip not available" when using the Python Imaging Library. The error has occurred when trying to work with PNGs or JPEGs or when loading the fonts supplied with PIL. I can work ...
Re: read large zip file   (79 Views)
En Sun, 06 Apr 2008 19:20:31 -0300, Brian Blais escribi: > I need to read a series of large zipfiles (which only contain one > large text file), and I noticed that the zipfile module: > > 1) has ...
Windows gzip problem   (62 Views)
, I am having a problem with gzip. The code worked fine under linux but when I moved it over to windows it is getting stuck unzipping a gz file. -- snippet -- fileObj = gzip.GzipFile(iceGetter.file.localFileName, 'rb') uncompressedFileName = iceGetter.file.localFileName[:-3] ...
How to get number of compressed bytes from GzipFile   (64 Views)
Hi all, I'm using the gzip module to return a gzip response from a small python httpserver. I'd like to know the number of bytes written to the underlying socket, but it doesn't seem to support the tell() function. This ...
import gzip error (please help)   (81 Views)
Dear all, Please help, i have error message when i import gzip module. The error like this below: bash-3.00$ python Python 2.5 (r25:51908, Sep 20 2006, 03:46:40) [GCC 3.4.6] on sunos5 Type "help", "copyright", "credits" or "license" for more information. ...
Python CGI - Presenting a zip file to user   (95 Views)
Hi all, I'm working on a cgi script that zips up files and presents the zip file to the user for download. It works fine except for the fact that I have to overwrite the file using the same filename ...