Hongmu Notes

python

Python language interpreter

100% Browser local processing 0 Data upload

Common examples

Start REPL (interactive shell)

python

Execute specific Python file

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

Enter the REPL after executing a specific Python file

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

Execute Python expressions

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

Run a script for a specific module

python -m {{模块}} {{参数}}

Install packages using `pip`

python -m pip install {{包}}

Interactively debug Python scripts

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

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

python -m http.server

Tip: curly braces{{…}}It is the parameter that needs to be replaced (path, file name, etc.); the command is only executed in the local terminal, and this site does not save any input.

English original text comparison

Expand English instructions and examples (source 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

command information

command namepython
PurposePython language interpreter
Applicable platforms通用
Number of examples8 Article
Official documentationhttps://docs.python.org/using/cmdline.html
Data sourcetldr-pages(CC-BY-4.0)· Community Chinese Translation

FAQ

python What does the command do?

Python language interpreter

python How to use it?

Pages listed by scene8Commonly used examples: Each example first explains the purpose, and then gives a complete command that can be directly copied (the parameters that need to be replaced are in the curly brackets).

python What are the most commonly used operations?

Start REPL (interactive shell):python

What do the curly braces in the command mean?

curly braces{{…}}Indicates that you need to replace it with your own value, such as path and file name; square brackets for parameters with the same name (such as[-C|--directory]) indicates optional writing.