Tuesday, June 10, 2014

Relative Paths In Scripts Run By Crontab - Python

I learned that a script run by crontab can't have a relative path.

This fix was here: http://stackoverflow.com/a/10422444

The following example opens my_file.txt in a path relative to your script:
import os
dir_path = os.path.dirname(os.path.abspath(__file__))
with open (os.path.join(dir_path, 'my_file.txt'), "r") as myfile:
    mytext = myfile.read()

No comments:

Post a Comment