for-loop in Python Function Prevents Further Iterations of Function from Working

前端 未结 1 1464
感动是毒
感动是毒 2021-01-29 01:04

I have a Flask application that runs python functions that isn\'t working properly. I have identified the source of the problem to be a for loop within a function, but I don\'t

1条回答
  •  情歌与酒
    2021-01-29 01:27

    I have solved this myself. The problem lies in the function "searchXML", which is called in the for loop. The function utilizes the line

    os.chdir('/Users/dinakarguthy/Documents/audit_sample')
    

    but the line that opens the file is simply

    f = open('output.html', 'w')
    

    I open the file with a relative pathname, instead of an absolute, which is the problem. After the for loop is run my directory is changed to a different one, and so a different output.html file is created/edited in that otehr directory. However, my function still opens up a tab with the 'output.html' that is still in the original directory.

    0 讨论(0)
提交回复
热议问题