红穆笔记

python

Python 語言解釋器

100% 瀏覽器本地處理 0 數據上傳

常用示例

啓動 REPL(交互式 shell)

python

執行特定 Python 文件

python {{路徑/到/文件.py}}

執行特定 Python 文件後進入 REPL

python -i {{路徑/到/文件.py}}

執行 Python 表達式

python -c "{{表達式}}"

運行特定模塊的腳本

python -m {{模塊}} {{參數}}

使用 `pip` 安裝包

python -m pip install {{包}}

互動調試 Python 腳本

python -m pdb {{路徑/到/文件.py}}

在當前目錄中的端口 8000 上啓動內置的 HTTP 服務器

python -m http.server

提示:花括號{{…}}是需要替換的參數(路徑、文件名等);命令只在本機終端執行,本站不保存任何輸入。

英文原文對照

展開英文說明與示例(來源 tldr-pages)

Python language interpreter. More information

Start a REPL (interactive shell)

python

Execute a specific Python file

python {{path/to/file.py}}

Execute a specific Python file and start a REPL

python -i {{path/to/file.py}}

Execute a Python expression

python -c "{{expression}}"

Run the script of the specified library module

python -m {{module}} {{arguments}}

Install a package using `pip`

python -m pip install {{package}}

Interactively debug a Python script

python -m pdb {{path/to/file.py}}

Start the built-in HTTP server on port 8000 in the current directory

python -m http.server

命令信息

命令名python
用途Python 語言解釋器
適用平臺通用
示例數量8 條
官方文檔https://docs.python.org/using/cmdline.html
數據來源tldr-pages(CC-BY-4.0)· 社區中文翻譯

常見問題

python 命令是做什麼的?

Python 語言解釋器

python 怎麼用?

頁面按場景列出了8 條常用示例:每條示例先說明用途,再給出可直接複製的完整命令(花括號裏是需要替換的參數)。

python 最常用的操作是什麼?

啓動 REPL(交互式 shell):python

命令裏的花括號是什麼意思?

花括號{{…}}表示需要替換成你自己的值,例如路徑、文件名;同名參數方括號(如 [-C|--directory])表示可選寫法。