2
def zipdir(dirpath):
    for foldername, subfolders, filenames in os.walk(dirpath):
        print("adding files in %s  " % (foldername))
        zf.write(foldername)
        for filename in filenames:
            zf.write(os.path.join(foldername,filename))
  • 1
    If a question isn't Raspberry Pi specific there is invariably a better site at which to ask the question. – joan Apr 16 '17 at 8:15
  • 1
    Per previous comments, this is a non-Pi specific programming problem which would be better asked on either StackOverflow or possibly Code Review. – goobering Apr 16 '17 at 11:28
2

If you mean the for foldername, subfolders, filenames in os.walk(dirpath): line, yes thats allowed. You do the same thing to iterate over dictionaries via the for key, value in {"key": "Value"}.items() style.

If you mean the for filename in filenames:

Yes, sub loops using in-scope variables are allowed too.

Not the answer you're looking for? Browse other questions tagged or ask your own question.