Python は現在の py ファイル パスを取得します。2 つの方法の違い

方法 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])

おすすめ

転載: blog.csdn.net/qq_41236493/article/details/115233099