the problem was not connected to loop, but to the temp file, I removed the section with NamedTemporaryFile and used mstemp instead, I think the file got deleted before I was finished with reading.
But python rocks.
try this:
for i in tar.getnames():
or if you want tarinfoobjects:
for i in tar.getmembers():
on tarinfo objects you can use the "name" attribute,
good luck and look out for cactus, he's an evil Ruby zealot
]]> def readDB(self, db):
tar = tarfile.open(db, 'r')
for tarinfo in tar:
print tarinfo.name, "is", tarinfo.size, "bytes in size and is",
if tarinfo.isreg():
print "a regular file."
elif tarinfo.isdir():
print "a directory."
else:
print "something else."
tar.close()
works:
file = urllib2.urlopen(url)
f = open("out.tar.gz", "w")
copyfileobj(file, f)
file.close()
f.close()
readDB("out.tar.gz")
does not work
file = urllib2.urlopen(url)
tmp = NamedTemporaryFile( "w")
copyfileobj(file, tmp)
file.close()
readDB(tmp.name)
tmp.close()