株式会社リュディアです。今回は Python のコマンドライン引数についてまとめてみます。Jupyter Notebook を使っておられる方は少し設定が面倒になるので今回は Windows のコマンドプロンプトから Python を実行します。Windows のコマンドプロンプトで Python が実行 ...
Pythonでスクリプト(プログラム)を作成する際、ファイル名や処理回数などの値を、プログラムの中に直接書き込んで(ハードコーディングして)いませんか? 「処理するファイルを変えるたびに、コードを書き換えて保存し直す」 これは非常に手間です ...
# コマンドライン引数をオプションの形(-X 値/-X)で指定する例 # 以下の辞書で値がTrueのオプションは、続けてその値を指定するもの # 値がFalseのオプションは何らかのスイッチ(True/False値を持つ) # 例:python3 kw_args.py -x hoge -y huga -z options = {'-x': True, '-y ...
A script that hardcodes its input (a filename, a search string, a mode of operation) only does one thing. Every time you need it to do something slightly different, you have to edit the source code.
While the os module focuses on the operating system itself, the sys module lets you interact directly with the running Python interpreter. It provides variables and functions that control command-line ...