コマンドラインでPythonスクリプトを実行する
Jupyter Notebook や Spyder のようなGUIを開かずに、コマンドラインでPythonを使う方法を例で確認しましょう。コマンドラインでPythonとやり取りするほうが、GUIよりも速く効率的です。ここでは、Pythonファイルを作成し、bashターミナルから離れずにネイティブのPythonで実行します。
この演習はコースの一部です
シェルでのデータ処理
演習の手順
- 1回の操作で新しいPythonファイルを作成し、Pythonのprintコマンドをそのファイルに渡してください。
- コマンドラインからそのファイルを直接呼び出して、新しいPythonファイルを実行してください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# in one step, create a new file and pass the print function into the file
echo "print('This is my first Python script')" ___ my_first_python_script.py
# check file location
ls
# check file content
cat my_first_python_script.py
# execute Python script file directly from command line
___ my_first_python_script.___