zipfile

renaming the extracted file from zipfile

牧云@^-^@ 提交于 2021-02-07 12:14:45
问题 I have lots of zipped files on a Linux server and each file includes multiple text files. what I want is to extract some of those text files, which have the same name across zipped files and save it a folder; I am creating one folder for each zipped file and extract the text file to it. I need to add the parent zipped folder name to the end of file names and save all text files in one directory. For example, if the zipped folder was March132017.zip and I extracted holding.txt, my filename

Split a zip archive into multiple chunks

陌路散爱 提交于 2021-02-05 05:34:10
问题 I'm trying to create a zip archive of a possibly huge folder. For this purpose I'm using the python zipfile module, but as far as I can see there is no option to split the created archive into multiple chunks with a max size. The zipped archive is supposed to be sent via Telegram, which has a size limitation of 1.5 GB per file. Thereby I need to split the resulting zip archive. I would really like to not use a subprocess and shell commands for creating this archive. My current code looks like

Split a zip archive into multiple chunks

我的未来我决定 提交于 2021-02-05 05:33:09
问题 I'm trying to create a zip archive of a possibly huge folder. For this purpose I'm using the python zipfile module, but as far as I can see there is no option to split the created archive into multiple chunks with a max size. The zipped archive is supposed to be sent via Telegram, which has a size limitation of 1.5 GB per file. Thereby I need to split the resulting zip archive. I would really like to not use a subprocess and shell commands for creating this archive. My current code looks like

Renaming ZipFile in Python

帅比萌擦擦* 提交于 2021-01-28 19:59:26
问题 To rename the one file in a ZipFile that I'm downloading, I do the following: for item in zipfile.infolist(): old_name = item.filename match = re.search(r'(.*)(.mdb)', item.filename) item.filename = "%s_friend%s" % (match.group(1),, match.group(2)) # I should probably be using replace here zipfile.extract(old_name, save_dir) However when I want to extract that file and save it into a specific directory, I need to reference the "old_name" and cannot reference the new. Is there a "cleaner" way

Zipfile in Python file permission

六眼飞鱼酱① 提交于 2021-01-27 20:26:00
问题 i used zipfile lib to extract file from zip and now after unzip the directory i found the permission of my file has been corrupted , import zipfile fh = open('sample.zip', 'rb') z = zipfile.ZipFile(fh) print z.namelist() for name in z.namelist(): z.extract(name, '/tmp/') fh.close() but when i use linux unzip tools this issue don't happen i try to use os.system('unzip sample.zip') but i still want to do this with zipfile 回答1: The related Python issues provide some insight as to why the issue

Accessing extracted zip file in Colab

微笑、不失礼 提交于 2020-12-14 11:43:56
问题 Some case study here. I am trying to play with PIL library in Google Colab, and can't get ImageFont to read my originally zipped file. The code: import requests, zipfile, io r3 = requests.get('https://sources.archlinux.org/other/community/ttf-roboto/ttf-roboto-hinted-2.138.zip') z3 = zipfile.ZipFile(io.BytesIO(r3.content)) z3.extractall() So far so good, and if I browse my directory with ls, it shows me the elements: ls Shows: LICENSE RobotoCondensed-Regular.ttf __MACOSX/ Roboto-Italic.ttf

Accessing extracted zip file in Colab

放肆的年华 提交于 2020-12-14 11:40:50
问题 Some case study here. I am trying to play with PIL library in Google Colab, and can't get ImageFont to read my originally zipped file. The code: import requests, zipfile, io r3 = requests.get('https://sources.archlinux.org/other/community/ttf-roboto/ttf-roboto-hinted-2.138.zip') z3 = zipfile.ZipFile(io.BytesIO(r3.content)) z3.extractall() So far so good, and if I browse my directory with ls, it shows me the elements: ls Shows: LICENSE RobotoCondensed-Regular.ttf __MACOSX/ Roboto-Italic.ttf

Accessing extracted zip file in Colab

怎甘沉沦 提交于 2020-12-14 11:40:17
问题 Some case study here. I am trying to play with PIL library in Google Colab, and can't get ImageFont to read my originally zipped file. The code: import requests, zipfile, io r3 = requests.get('https://sources.archlinux.org/other/community/ttf-roboto/ttf-roboto-hinted-2.138.zip') z3 = zipfile.ZipFile(io.BytesIO(r3.content)) z3.extractall() So far so good, and if I browse my directory with ls, it shows me the elements: ls Shows: LICENSE RobotoCondensed-Regular.ttf __MACOSX/ Roboto-Italic.ttf

Read ZipFile from URL into StringIO and parse with panda.read_csv

别说谁变了你拦得住时间么 提交于 2020-12-06 06:59:12
问题 I'm trying to read ZipFile data from a URL and via StringIO parse the data inside the ZipFile as csv using pandas.read_csv r = req.get("http://seanlahman.com/files/database/lahman-csv_2014-02-14.zip").content file = ZipFile(StringIO(r)) salaries_csv = file.open("Salaries.csv") salaries = pd.read_csv(salaries_csv) The last line gave me an error: CParserError: Error tokenizing data. C error: Calling read(nbytes) on source failed. Try engine='python'. However if i try using salaries = pd.read