python os.walk returns nothing
<p>I have a problem with using <code>os.walk</code> on Mac. If I call it from <code>python terminal</code>, it works perfect, but if I call it via a <code>python script</code>, it returns empty list. For example:</p>

<pre><code>    import os

    path = "/Users/temp/Desktop/test/"
    for _ ,_ , files in os.walk(path):
        test = [my_file for my_file in files]

    print test
</code></pre>

<p>then, it prints:</p>

<pre><code>    []
</code></pre>

<p>and I am pretty sure that the <code>path</code> does exists.
Any idea what is the problem? </p>

<p>You most likely need to intantiate the test list outside the for loop, for this to work.</p>

<pre><code>import os

path = "/Users/temp/Desktop/test/"
test = []
for _ ,_ , files in os.walk(path):
    test.extend([my_file for my_file in files])

print test
</code></pre>

python