Writing to a text file within a module

I recently wrote a module, and it does what I want it to, but I have one issue. Within the module, I want to write some of the data to a text file, but I’m having trouble doing so. If I have some simple python code to write to a text file within a module, when I run my pipeline with that module in it, should I expect to see that text file in my files? If not, why? Right now I can’t find the text files that I’m writing within my modules. Thank you!

Matt Papke

Without seeing the code itself, I have a few suggestions:

  • Can you confirm that the run of your module is in fact reaching the code in question? E.g., can you put a simple “Hello world” print statement or some such and see it in the terminal output?
  • If ‘yes’ to the above, if only the text file filename is specified but not the associated path, then it might be writing it to the cellprofiler installation folder.
  • If you want to hard-code where the files go, you might need to configure the path that the text file is being written to, which is typically done with the path
    commands in Python. - Alternately, you could try to add user-specification of the path as a module setting, in much the same way as ExportToSpreadsheet does; you’ll need to check out the source code for that module to see how it’s done.

Without seeing the code itself, I have a few suggestions:

  • Can you confirm that the run of your module is in fact reaching the code in question? E.g., can you put a simple “Hello world” print statement or some such and see it in the terminal output?
  • If ‘yes’ to the above, if only the text file filename is specified but not the associated path, then it might be writing it to the cellprofiler installation folder.
  • If you want to hard-code where the files go, you might need to configure the path that the text file is being written to, which is typically done with the path
    commands in Python. - Alternately, you could try to add user-specification of the path as a module setting, in much the same way as ExportToSpreadsheet does; you’ll need to check out the source code for that module to see how it’s done.

Thank you so much, that’s exactly where I found them!

Matt