[SciPy-User] Curse of recursive directory walking

Gökhan SEVER gokhansever at gmail.com
Wed Jul 29 10:30:20 EDT 2009


I have a simple Python script which is written with a purpose to walk
through the given root directory and spot and read the right data files and
plot some of the desired variables within them for the first stage data
inspection.

The script named (dccn_plot_all.py) is given as below --while dccn_plot
being the main action script:


#!/usr/bin/env python

# dccn_plot_all

import os
from subprocess import call

init = os.getcwd()

for root, dirs, files in os.walk('.'):
    for file in files:
        if file.split('.')[1] == 'sau' and not file.endswith('.nc'):
            print file
            os.chdir(root)
            print os.getcwd()
            call(['dccn_plot', file])
            os.chdir(init)


Here is the fun part: While I was testing the script, I mistakenly called
this dccn_plot_all script itself within the os.walk suite. And this was
resulted with a almost complete lose of my Bash shell access on my Fedora 11
and made windows manager also unreachable. To recover, I had to restart the
system.

The lesson learnt: be extremely cautious while working in the nearby of
recursive functions.

-- 
Gökhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20090729/8e2af667/attachment.html>


More information about the SciPy-User mailing list