0

I am currently trying to debug an app that I have not written myself. I have narrowed the problem down to a particular method that is imported from a module outside of the current script. I would like to step through this module by writing to a file at each step, however it doesn't seem to work.

I have a version of the app that is running correctly and when I write to a file from within the module, the script runs fine but no file is created. Am I missing something here?

Example

Script that I am debugging

from module import method

example code ...
method(data)   ---  where error occurs
more code ...

module.py

def method(data):
    file = open('filetowrite.txt','w')
    file.write('something ....')
    file.close()

2 Answers2

1

Do not reinvent the wheel, use standard logging module.

Since you mentioned "I would like to step through this module" that's how you can do it with again standard pdb module.

Vor
  • 33,215
  • 43
  • 135
  • 193
0

Your code for file writing looks fine. I would look at the path (the location) where the file is being written to.

Check out:

How to get full path of current file's directory in Python?

Community
  • 1
  • 1
Jesuisme
  • 1,805
  • 1
  • 31
  • 41
  • 1
    also try opening it in `w+` instead of just `w` which means if it doesn't exist it will create it and not throw an error. – Joe Smart Sep 18 '14 at 14:49