LoginSignup
29

More than 5 years have passed since last update.

posted at

updated at

実行スクリプトからの相対パスでファイルにアクセスする.

実行スクリプト名は__file__で取得できる.
これとos.pathモジュールを組み合わせて,実行スクリプトから相対パスでファイルにアクセスする.

base = os.path.dirname(os.path.abspath(__file__))
name = os.path.normpath(os.path.join(base, '../local/local_db'))

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
29