Info
Content

Cron and Python

Very often I end up using and working with external files in Python, and occasionally I use the task scheduler Cron.

However, when working with files using relative paths, Cron can cause issues, as all jobs are executed in the user's home directory, causing Python to work with the wrong files or just not work at all.

In order to fix this, we can use os.chdir() to change where our script is running.

import os
os.chdir("/home/pi")
No Comments
Back to top