2011年8月7日日曜日

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

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

0 件のコメント: