Script Discussion & Critique

Bruno Desthuilliers bdesth.nospam at removeme.free.fr
Thu Aug 28 02:30:28 EDT 2003


hokiegal99 wrote:
> derek / nul wrote:
> 
>> here will do
> 
> 
> OK, I have a few questions about the script at the end of this message:
> 
> Is this script written well? Is it a good design? How could it be made 
> better (i.e. write to a file exactly what the scipt did)? I hope to use 
> it to recursively find a replace strings in all types of files (binary 
> and text).
> 
> Thanks for any ideas, pointers or critique... most of the ideas behind 
> the script came from the list.
> 


Err... Is this my version of Python having troubles, or could it be 
possible that nobody actually took time to *test* that script ?
There is a real problem on line 15:
 > for root, dirs, files in os.walk(setpath):

on Python 2.2.2, here is what I get :

[laotseu at localhost dev]$ python rfp.py
(snip)
Traceback (most recent call last):
   File "rfp.py", line 15, in ?
     for root, dirs, files in os.walk(setpath):
AttributeError: 'module' object has no attribute 'walk'
[3]+  Done                    emacs testrfp
[laotseu at localhost dev]$


Of course, 'walk' is in os.path, not in os.

Python 2.2.2 (#2, Feb  5 2003, 10:40:08)
[GCC 3.2.1 (Mandrake Linux 9.1 3.2.1-5mdk)] on linux-i386
Type "help", "copyright", "credits" or "license" for more information.
 >>> import os
 >>> os.walk
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
AttributeError: 'module' object has no attribute 'walk'

Now a another problem on the same line :
 >>> for root, dirs, files in os.path.walk(setpath):
...     print root, dirs, files
...
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: walk() takes exactly 3 arguments (1 given)

Of course, this is not the syntax nor the way to use os.path.walk

I checked the os module for a function with similar syntax and usage, 
and could not find one. os.listdir would have been a candidate, but it 
does not recurse, and do not return a (root, dirs, files) tuple but a 
list of filenames.

So what ?

Bruno





More information about the Python-list mailing list