Xử lý dữ liệu trên Shell
Susan Sun
Data Person
Python
Tài liệu:
man python
...
-V , --version
In phiên bản Python của tệp thực thi rồi thoát.
python --version
Python 3.5.2
Ví dụ: dùng Python hệ thống
which python
/usr/bin/python
Kích hoạt phiên Python tương tác trong terminal:
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.
>>>
Trong phiên tương tác, chỉ dùng cú pháp Python:
>>> print('hello world')
hello world
Thoát phiên Python và về terminal:
>>> exit()
$
Phiên tương tác Python:
Cách khác:
.pypython + tên fileCách 1
.py bằng trình soạn thảo trên dòng lệnh (vd: nano, Vim, Emacs)
Cách 2
.py bằng cách echo cú pháp Python vào file hello_world.py, đồng thời khởi tạo file.echo "print('hello world')" > hello_world.py
Kiểm tra nhanh nội dung file:
cat hello_world.py
print('hello world')
Bảo đảm đang ở cùng thư mục với file .py:
ls
hello_world.py
Chạy file .py bằng cách đặt trước tên file python:
python hello_world.py
hello world
Xử lý dữ liệu trên Shell