using tarfile with an open file object

  • Thread starter Matthew Thorley
  • Start date
M

Matthew Thorley

I've been using tarfile like this

import tarfile
tar = tarfile.open('path_to_tar_archive', 'r:gz')


But I need to use it like this:

archive = open('path_to_tar_archive', 'r')
tar = tarfile.open(archive.readlines())

or something similar. In essence I need to use tarfile to manipulate an
already open file object. I searched in the docs but didn't find
anything. Maybe I just over looked the obvious.

Does any one know how to do this?

Thanks
-matthew
 
P

Peter Hansen

Matthew said:
I've been using tarfile like this

import tarfile
tar = tarfile.open('path_to_tar_archive', 'r:gz')


But I need to use it like this:

archive = open('path_to_tar_archive', 'r')
tar = tarfile.open(archive.readlines())

or something similar. In essence I need to use tarfile to manipulate an
already open file object. I searched in the docs but didn't find
anything. Maybe I just over looked the obvious.

Does any one know how to do this?

I don't know if this is in the docs (please check and submit a bug
report if it's not), but the source shows that you should be able to do
this:

tar = tarfile.open(fileobj=archive)

and carry on as you wish.

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top