Python variables scope in loops example
<p>I am new with Python and confused regarding the scope of variables which are declared inside loops. I have seen some examples but it is hard for me to understand it in my specific case.</p>

<p>For example, I saw the following code segment <a href="https://stackoverflow.com/questions/36285502/how-to-extract-zip-file-recursively-in-python">here</a>: </p>

<pre><code>with ZipFile(self.archive_name, "r") as archive:
    for id, files in data.items():
        if files:
            print("Creating", id)
            dirpath = os.path.join(directory, id)

            os.mkdir(dirpath)

            for file in files:
                match = pattern.match(filename)
                new = match.group(2)
                new_filename = os.path.join(dirpath, new)

                content = archive.open(file).read()
            with open(new_filename, "wb") as outfile:
                outfile.write(content)
</code></pre>

<p>I basically have the <strong>above code repeated</strong> in very much the same way but with different statements executed inside the loops. <strong>These similar code segments are one after the other inside my <code>__main__</code>.</strong> My question is: in that <em>repeated code</em> do I <strong>need to give new names to the variables</strong> for <code>archive</code>, <code>id</code>, <code>file</code>, <code>files</code>, <code>outfile</code> or not? Will there be a clash or something? Are there any <em>good-practice</em> concerns to keep in mind?</p>