471,071 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

using tarfile with an open file object

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
Jul 19 '05 #1
1 2485
Matthew Thorley wrote:
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
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Josh Smith | last post: by
5 posts views Thread by Hans-Joachim Widmaier | last post: by
8 posts views Thread by Jay Donnell | last post: by
3 posts views Thread by justin.vanwinkle | last post: by
3 posts views Thread by John Salerno | last post: by
7 posts views Thread by aurora00 | last post: by
1 post views Thread by boblatest | last post: by
reply views Thread by leo001 | last post: by

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.