Documentation: Extraction of single files
LuminairPrime opened this issue · comments
This code snippit on the front page doesn't run for me. I think SevenZipFile needs to be py7zr.SevenZipFile, and I get this error about the brackets and "for":
selective_files = [f if filter_pattern.match(f) for f in allfiles]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: expected 'else' after 'if' expression
filter_pattern = re.compile(r'<your/target/file_and_directories/regex/expression>')
with SevenZipFile('archive.7z', 'r') as archive:
allfiles = archive.getnames()
selective_files = [f if filter_pattern.match(f) for f in allfiles]
archive.extract(targets=selective_files)
I'm just learning, so I'm going through all this from the beginning. Thank you for the streamlined library!
Thank you for the feedback. It should be
selective_files = [f for f in allfiles if filter_pattern.match(f)]