Python/サンプル/スクリプト名を取得する
の編集
Top
/
Python
/
サンプル
/
スクリプト名を取得する
[
トップ
] [
編集
|
差分
|
バックアップ
|
添付
|
リロード
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
-- 雛形とするページ --
(no template pages)
#navi(../) * Pythonのスクリプト名を取得する [#l56c54ca] Pythonスクリプトのパス情報を除いたスクリプト名のみを取得する方法を記します。~ UNIXコマンドであれば、basenameの動作と同様です。 #contents #htmlinsertpcsp(ll-top.html,ll-sp.html) * 動作確認環境 [#x3953840] $ python --version Python 2.7.3 $ lsb_release -d Description: Ubuntu 12.04.4 LTS * 関連記事 [#vc4c6765] -[[Pythonスクリプトを実行しているパス(ディレクトリ)を取得する>Python/サンプル/スクリプトを実行しているパス(ディレクトリ)を取得する]] -[[Pythonスクリプトが存在するパス(ディレクトリ)を取得する>Python/サンプル/スクリプトが存在するパス(ディレクトリ)を取得する]] -[[Pythonのスクリプト名を取得する>Python/サンプル/スクリプト名を取得する]] * スクリプト名を取得する [#jfd7d8c1] 以下のサンプルコードおよび実行結果を参照してください。 ** サンプルコード [#x9861a2d] #ref(basename.py) import os basename = os.path.basename(__file__) print basename ** 実行結果 [#m40df147] 実際に実行したときの出力です。 sakura@ubuntu:~$ python python/basename.py basename.py スクリプト名のみ取得できています。 #htmlinsertpcsp(ll-btm.html,ll-sp.html)
タイムスタンプを変更しない
#navi(../) * Pythonのスクリプト名を取得する [#l56c54ca] Pythonスクリプトのパス情報を除いたスクリプト名のみを取得する方法を記します。~ UNIXコマンドであれば、basenameの動作と同様です。 #contents #htmlinsertpcsp(ll-top.html,ll-sp.html) * 動作確認環境 [#x3953840] $ python --version Python 2.7.3 $ lsb_release -d Description: Ubuntu 12.04.4 LTS * 関連記事 [#vc4c6765] -[[Pythonスクリプトを実行しているパス(ディレクトリ)を取得する>Python/サンプル/スクリプトを実行しているパス(ディレクトリ)を取得する]] -[[Pythonスクリプトが存在するパス(ディレクトリ)を取得する>Python/サンプル/スクリプトが存在するパス(ディレクトリ)を取得する]] -[[Pythonのスクリプト名を取得する>Python/サンプル/スクリプト名を取得する]] * スクリプト名を取得する [#jfd7d8c1] 以下のサンプルコードおよび実行結果を参照してください。 ** サンプルコード [#x9861a2d] #ref(basename.py) import os basename = os.path.basename(__file__) print basename ** 実行結果 [#m40df147] 実際に実行したときの出力です。 sakura@ubuntu:~$ python python/basename.py basename.py スクリプト名のみ取得できています。 #htmlinsertpcsp(ll-btm.html,ll-sp.html)
テキスト整形のルールを表示する
添付ファイル:
basename.py
456件
[
詳細
]