importUnRAR
# extract all the files in test.rar
UnRAR.Archive('test.rar').extract()
# extract all the files in test.rar matching the wildcard *.txt
UnRAR.Archive('test.rar').extract('*.txt')
# print the name and size of each file, extracting small ones
forfileInArchiveinUnRAR.Archive('test.rar').iterfiles():
printfileInArchive.filename,fileInArchive.size
iffileInArchive.size<=1024:
fileInArchive.extract()
# print the contents of any file whose name ends with test.txt
forfileInArchiveinUnRAR.Archive('test.rar').iterfiles():
iffileInArchive.filename.endswith('test.txt'):
printfileInArchive.open('rt').read()