工具 & 效率12 分钟阅读
Python 常用命令 100 条
本文整理 Python 3.14 环境中常用的 100 条命令与短代码,覆盖解释器、虚拟环境、依赖、文件数据、网络、并发、测试、调试、性能和打包。第三方工具需先安装,项目命令优先写成 python -m ...,避免调用到错误环境中的可执行文件。
2026年8月19日阅读—点赞—收藏—
dba100pythonruff墨力计划
在知识库中专注阅读,并随时返回相关工具与课程
本文整理 Python 3.14 环境中常用的 100 条命令与短代码,覆盖解释器、虚拟环境、依赖、文件数据、网络、并发、测试、调试、性能和打包。第三方工具需先安装,项目命令优先写成 python -m ...,避免调用到错误环境中的可执行文件。
👋 我是三笠丶,一名专注数据库与数据库架构的 DBA。更多原创文章和技术资料同步更新:ora100.com
本文整理 Python 3.14 环境中常用的 100 条命令与短代码,覆盖解释器、虚拟环境、依赖、文件数据、网络、并发、测试、调试、性能和打包。第三方工具需先安装,项目命令优先写成 python -m ...,避免调用到错误环境中的可执行文件。
1python3 --version1python3 -VV1python3 -c "import sys; print(sys.executable)"1python3 -c "import sys; print(*sys.path, sep='\n')"1python3 -c "import platform; print(platform.platform())"1python3 -c "print(sum(range(101)))"1python3 -m http.server 80001python3 -i app.py1python3 -I script.py1python3 --help-all1python3 -m venv .venv1source .venv/bin/activate1python -m pip install --upgrade pip1python -m pip install 'requests==2.32.5'1python -m pip install -r requirements.txt1python -m pip list1python -m pip list --outdated1python -m pip show requests1python -m pip check1python -m pip freeze > requirements-lock.txt1python3 -m pydoc json1python3 -m pydoc -p 80801python3 -c "import json; print(json.__file__)"1python3 -c "help('modules')"1python3 -m py_compile app.py1python3 -m compileall -q src1python3 -m ast app.py1python -m black .1python -m ruff check .1python -m mypy src1python3 -c "from pathlib import Path; print(Path('app.log').read_text(encoding='utf-8'))"1python3 -c "from pathlib import Path; Path('status.txt').write_text('ok\n', encoding='utf-8')"1python3 -c "from pathlib import Path; print(*Path('.').rglob('*.py'), sep='\n')"1python3 -c "import hashlib,pathlib; print(hashlib.file_digest(pathlib.Path('pkg.tgz').open('rb'),'sha256').hexdigest())"1python3 -m json.tool input.json1python3 -m json.tool input.json >/dev/null1python3 -c "import csv; print(*csv.DictReader(open('data.csv',encoding='utf-8')),sep='\n')"1python3 -m zipfile -c backup.zip data/1python3 -m zipfile -l backup.zip1python3 -m zipfile -e backup.zip restore/1python3 -c "from datetime import datetime,timezone; print(datetime.now(timezone.utc).isoformat())"1python3 -c "from datetime import date,timedelta; print(date.today()+timedelta(days=7))"1python3 -c "from datetime import datetime; print(datetime.strptime('2026-07-27','%Y-%m-%d'))"1python3 -c "import re; print(re.findall(r'\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b',open('app.log').read()))"1python3 -c "import re; print(re.sub(r'password=\\S+','password=***','user=a password=secret'))"1python3 -c "from urllib.parse import quote; print(quote('金仓 数据库'))"1python3 -c "import base64; print(base64.b64encode(b'hello').decode())"1python3 -c "import base64; print(base64.b64decode('aGVsbG8=').decode())"1python3 -c "import uuid; print(uuid.uuid4())"1python3 -c "import secrets; print(secrets.token_urlsafe(32))"1python3 -c "import socket; print(socket.gethostbyname_ex('example.com'))"1python3 -c "import socket; print(socket.create_connection(('127.0.0.1',8000),3).getpeername())"1python3 -c "from urllib.request import urlopen; print(urlopen('https://example.com',timeout=5).status)"1python3 -c "from urllib.parse import urlparse; print(urlparse('https://example.com/a?q=1'))"1python3 -c "import os; print(os.getenv('PATH'))"1python3 -c "from pathlib import Path; print(Path.cwd())"1python3 -c "import os; print(os.process_cpu_count())"1python3 -c "import subprocess; subprocess.run(['git','status','--short'],check=True)"1python3 -c "import subprocess; print(subprocess.check_output(['uname','-r'],text=True).strip())"1python3 -c "import resource; print(resource.getrlimit(resource.RLIMIT_NOFILE))"1python3 -m sqlite3 app.db1python3 -c "import sqlite3; print(sqlite3.connect('app.db').execute('select sqlite_version()').fetchone())"1python3 -c "import sqlite3; c=sqlite3.connect('app.db'); c.execute('create table if not exists t(id integer primary key,name text)'); c.commit()"1python3 -c "import sqlite3; a=sqlite3.connect('app.db'); b=sqlite3.connect('backup.db'); a.backup(b)"1python3 -c "import asyncio; asyncio.run(asyncio.sleep(1,result='done'))"1from concurrent.futures import ThreadPoolExecutor2with ThreadPoolExecutor(4) as pool:3 print(list(pool.map(str.upper, ["a", "b", "c"])))1from concurrent.futures import ProcessPoolExecutor2with ProcessPoolExecutor() as pool:3 print(list(pool.map(abs, [-1, -2, -3])))1from queue import Queue2q = Queue(); q.put("task"); print(q.get())1python3 -c "import subprocess; subprocess.run(['sleep','1'],timeout=2,check=True)"1import asyncio2async def main():3 await asyncio.gather(*(asyncio.to_thread(print, x) for x in range(5)))4asyncio.run(main())1python3 -m unittest discover -s tests -v1python3 -m unittest tests.test_api.ApiTest.test_health1python -m pytest -q1python -m pytest -k health -vv1python -m pytest -x1python -m coverage run -m pytest1python -m coverage report -m1python3 -m pdb app.py1python3 -m pdb -c continue app.py1python3 -X dev app.py1python3 -m timeit "sum(range(1000))"1python3 -m timeit -s "x=list(range(1000))" "sum(x)"1python3 -m cProfile -o profile.pstats app.py1python3 -c "import pstats; pstats.Stats('profile.pstats').sort_stats('cumulative').print_stats(20)"1python3 -X importtime -c "import asyncio"1python3 -X tracemalloc=10 app.py1python3 -X faulthandler app.py1python3 -W error app.py1python3 -B app.py1python3 -c "import gc; print(gc.get_stats())"1python -m pip install -U build1python -m build1python -m build --wheel1python -m twine check dist/*1python -m twine upload --repository testpypi dist/*1python -m pip install dist/example-1.0.0-py3-none-any.whl1python -m pip install -e .1python3 -m zipapp src -m 'app:main' -o app.pyz1python3 -m zipfile -l dist/example-1.0.0-py3-none-any.whl1python -m ruff check . && python -m pytest -q && python -m build这 100 条命令覆盖了 Python 项目从环境创建到发布的主要环节。生产项目应固定依赖版本、隔离运行环境、把检查与测试放入 CI,并避免在命令行或源码中保存密钥。
更多 Oracle、MySQL、PostgreSQL、MongoDB 实战内容,可以访问 DBA 学习平台:ora100.com
感谢阅读。 我会持续分享 Oracle、GoldenGate、RAC、Data Guard、MySQL、PostgreSQL、OceanBase、电科金仓等数据库技术文章。
个人网站:ora100.com