0

My code goes through the compiler but doesn't replace what needs to be replaced in the new file. All files are in the same directory and I've tried running it as ./06_1 but nothing changed. Here is the code. Any help would be appreciated.

def replace_and_chars(fname):

    f = open(fname,"r", encoding='windows-1255')
    file_buffer_contents = f.read()
    file_buffer_contents.replace("&","\\x26")
    fout = open(fname.replace(".xml","") + "replaced.xml","w+")
    fout.write(file_buffer_contents)
    fout.close
    f.close()
    
    past = replace_and_chars("06_1.xml")
rdas
  • 20,604
  • 6
  • 33
  • 46
  • 4
    `file_buffer_contents = file_buffer_contents.replace("&","\\x26")`. `replace` is not in-place. – Guy Sep 07 '22 at 11:22
  • 2
    The indentation error causes `past = replace_and_chars("06_1.xml")` to be part of the function's definition, making it recursive. Thus you are not calling the function at all after defining it (and if you would, it would create an endless loop). – tripleee Sep 07 '22 at 11:28

0 Answers0