方法 1
現在のpyファイルの絶対パスを取得します。
import re
dirname, filename = os.path.split(os.path.abspath(__file__))
方法 2
プログラムエントリの絶対パスを取得します。
import os
import sys
dirname, filename = os.path.split(os.path.abspath(sys.argv[0]))
os.path.realpath(sys.argv[0])
現在のpyファイルの絶対パスを取得します。
import re
dirname, filename = os.path.split(os.path.abspath(__file__))
プログラムエントリの絶対パスを取得します。
import os
import sys
dirname, filename = os.path.split(os.path.abspath(sys.argv[0]))
os.path.realpath(sys.argv[0])