從 zip檔案中讀取資料

2021-10-25 03:29:10 字數 397 閱讀 7358

python 能夠直接讀取 zip 檔案中的資料。我們現在需要實現這樣乙個小任務:直接讀取乙個 zip 檔案,獲取裡面包含的檔案列表以及每個檔案的大小。

python 的 zipfile 模組可以輕鬆地幫助我們解決這個任務:

import zipfile

z = zipfile.zipfile("test.zip", "r")

for filename in z.namelist():

print filename

bytes = z.read(filename)

print len(bytes)

這裡需要注意地是 zipfile 模組有些 zip 檔案是無法處理,具體是裡面插入了注釋的 zip 檔案或者多分卷的 zip 檔案。

讀取zip檔案

public class ziptest public static void main string args throws filenotfoundexception,ioexception zipinputstream zis new zipinputstream new fileinputs...

從XML檔案中讀取資料

using system using system.data using system.configuration using system.web using system.web.security using system.web.ui using system.web.ui.webcontro...

從fig檔案中讀取資料

open figname.fig h get gca,children data get h,cdata 2 如果你的fig檔案中影象是由單條曲線繪製而成,比如說plot命令生成的,通過以下方式輸出橫座標,縱座標的取值 open figname.fig h line get gca,children...