2011年8月7日日曜日

実行ファイルの親ディレクトリのパスを取得

Pythonでプログラムを実行しているファイルの親ディレクトリのパスを取得する方法
import os
parent_path = os.path.abspath(os.path.dirname(__file__))
print parent_path
例えば、/workspace/src/test.pyで実行した場合、parent_pathは'/workspace/src'となる

0 件のコメント: