2020年4月22日水曜日

Get absolute path for script file and directory in Python.

When using CRON and python, it happens the file path is not where you meant. That is from the fact working directory for CRON  is /bin/... or somewhere.

Easy solution is to set absolute path for script file and directory.
# Give absolute filepath and directory
import os
# getcwd gives where script called
# os.getcwd()
# Absolute path of script
abs_path_ = os.path.abspath(__file__)
# Directory where script is
dir_ = os.path.dirname(abs_path)

0 件のコメント:

コメントを投稿