Forums

Always On task, file issue

Hi everyone,

I'm having an issue with running a Python script as an always-on task on PythonAnywhere. I have a few files in the same directory as my Python script. When I run the script from the bash terminal, it works perfectly and reads the files just fine using relative paths (e.g., "file.txt"). However, when I set it up as an always-on task, the script seems to find the files but reads them as if they are empty.

Is this happening because I'm using a relative path instead of the full file path? Do I need to specify the absolute path of each file for it to work correctly in an always-on task? Any guidance on why this might be happening or how to fix it would be greatly appreciated!

Thanks in advance!

You need to specify the path while taking the working directory into account. If you ignore the working directory, then relative paths will point to random places. The working directory for always on tasks is ~. See https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/