String find and replace

hokieghal99 hokiegal99 at
Wed Aug 27 01:22:06 CEST 2003

import os, string
print " "
setpath = raw_input("Enter the path: ")
def find_replace(setpath):
    for root, dirs, files in os.walk(setpath):
       fname = files
       for fname in files:
          find = string.find(file(os.path.join(root,fname), 
'rb').read(), 'THIS')
          print find
          if find >=1:
              replace = string.replace(str, 'THIS', 'THAT')
print " "

Why doesn't this work? I get this error:

Traceback (most recent call last):
   File "", line 12, in ?
   File "", line 11, in find_replace
     replace = string.replace(str, 'THIS', 'THAT')
   File "/usr/local/lib/python2.3/", line 370, in replace
     return s.replace(old, new, maxsplit)
TypeError: expected a character buffer object

More information about the Python-list mailing list