在 Shell 中進行資料處理
Susan Sun
Data Person
Python
文件:
man python
...
-V , --version
Prints the Python version number of the executable and exits.
python --version
Python 3.5.2
範例:使用系統內建的 Python
which python
/usr/bin/python
在終端機啟動互動式 Python:
python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linuxType "help", "copyright", "credits" or
"license" for more information.
>>>
在互動式環境內只能用 Python 語法:
>>> print('hello world')
hello world
離開 Python 回到終端機:
>>> exit()
$
Python 互動式環境:
替代作法:
.py 腳本python + 檔名 執行腳本方法 1
.py 檔(如 nano、Vim、Emacs)
方法 2
echo 將 Python 語法寫入 hello_world.py,同時建立檔案。echo "print('hello world')" > hello_world.py
檢查檔案內容:
cat hello_world.py
print('hello world')
確認你與 .py 檔在同一資料夾:
ls
hello_world.py
以 python 加檔名來執行 .py 檔:
python hello_world.py
hello world
在 Shell 中進行資料處理