tarfile

Can pandas read and archive within an archive?

Can pandas read and archive within an archive? Question: I have an archive file (archive.tar.gz) which contains multiple archive files (file.txt.gz). If I first extract the .txt.gz files to a folder, I can then open them with pandas directly using: import pandas as pd df = pd.read_csv(‘file.txt.gz’, sep=’t’, encoding=’utf-8′) But if I explore the archive …

Total answers: 3

Getting a single file from a tar file using the tarfile lib in python

Getting a single file from a tar file using the tarfile lib in python Question: I am trying to grab a single file from a tar archive. I have the tarfile library and I can do things like find the file in a list with the right extension: like their example: def xml_member_files(self,members): for tarinfo …

Total answers: 3

Read Contents Tarfile into Python – "seeking backwards is not allowed"

Read Contents Tarfile into Python – "seeking backwards is not allowed" Question: I am new to python. I am having trouble reading the contents of a tarfile into python. The data are the contents of a journal article (hosted at pubmed central). See info below. And link to tarfile which I want to read into …

Total answers: 4

How to construct a TarFile object in memory from byte buffer in Python 3?

How to construct a TarFile object in memory from byte buffer in Python 3? Question: Is it possible to create a TarFile object in memory using a buffer containing the tar data without having to write the TarFile to disk and open it up again? We get the bytes sent over a socket. Something like …

Total answers: 2

Python tarfile module overwrites existing files during extraction – how to disable it?

Python tarfile module overwrites existing files during extraction – how to disable it? Question: Is there a way prevent tarfile.extractall (API) from overwriting existing files? By “prevent” I mean ideally raising an exception when an overwrite is about to happen. The current behavior is to silently overwrite the files. Asked By: Sridhar Ratnakumar || Source …

Total answers: 3

How to create full compressed tar file using Python?

How to create full compressed tar file using Python? Question: How can I create a .tar.gz file with compression in Python? Asked By: shahjapan || Source Answers: import tarfile tar = tarfile.open(“sample.tar.gz”, “w:gz”) for name in [“file1”, “file2”, “file3”]: tar.add(name) tar.close() If you want to create a tar.bz2 compressed file, just replace file extension name …

Total answers: 10

Size of an open file object

Size of an open file object Question: Is there a way to find the size of a file object that is currently open? Specifically, I am working with the tarfile module to create tarfiles, but I don’t want my tarfile to exceed a certain size. As far as I know, tarfile objects are file-like objects, …

Total answers: 5