python: Inline script metadata

python脚本自动运行:

#!/usr/bin/env -S uv run --script
#!/usr/bin/env python
# /// script
# requires-python = ">=3.11"
# dependencies = [
#   "requests<3",
#   "rich",
# ]
# ///

import requests
from rich.pretty import pprint

resp = requests.get("https://peps.python.org/api/peps.json")
data = resp.json()
pprint([(k, v["title"]) for k, v in data.items()][:10])

注:如果用uv就用第1行,否则用第2行

posted @ 2025-03-31 10:16  卓能文  阅读(21)  评论(0)    收藏  举报