Forums

Best Practices for working Local and uploading to server on PythonAnywhere

Hello,

Looking for advice on best practices in terms of working locally and uploading to pythonanywhere.

What is the best way to set up the project so that path isn't so much an issue?

For example, when I upload code to python anywhere, the root path is at /home/myusername/mysite/ while when I'm working locally I use relative paths (within my project as contained by Git).

Thank you so much for your advice.

You can build your absolute path independent of the place you run your code.

import os
THIS_FOLDER = os.path.dirname(os.path.abspath(__file__))
my_file = os.path.join(THIS_FOLDER, 'myfile.txt')