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))

closed as off-topic by joan, goobering Apr 16 '17 at 11:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – joan, goobering
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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.