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

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

then, it prints:

    
    
        []
    

and I am pretty sure that the `path` does exists. Any idea what is the
problem?


Answer: You most likely need to intantiate the test list outside the for loop, for
this to work.

    
    
    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
    

