文件下载

http://topic.csdn.net/t/20060920/16/5035915.html

 

最近看到一个用于读取Rar压缩文件的库,比较有意思,解决python不能解压rar文件的问题。

下面这个地址是下载链接:

http://grue.l-t.ee/~marko/src/rarfile/

下载解压后会有一个rarfile.py的文件,可以直接引用。下面是一个简单的示例。

# add the rarfile path
import sys
import os

sys.path.insert(1, os.path.join(sys.path[0], './rarfile-1.0'))

from rarfile import RarFile
'''
RarFile(archive)

Creates new RarFile instance and reads Rar directory from archive.
namelist()

Return list of filenames.
infolist()

Return list of RarInfo items.
getinfo(filename)

Returns a RarInfo instance for specific file.
read(filename)

Read file contents.
close(filename)

Free open resources. Currently it does nothing.
'''

def openRarFile(filename):
rar=RarFile(filename)
print 'the file list',rar.namelist()
print 'the info list',rar.infolist()
for file in rar.namelist():
print 'the content of file %s' % file
print rar.read(file)
rar.close()

def main():
openRarFile('zipfiles.py.rar')
return 0

if __name__ == '__main__': main()

你可能感兴趣的:(python,list,File,import,archive)