
概念指南
Python 中如何在使用 format/f-string 时输出花括号字符 {}?
Python 字符串中输出字面花括号:format 用 {{ }} 转义;f-string 用 {{ }} 转义。本文介绍各种格式化方式中的花括号转义。
聚焦概念、架构、排障、价格与选型,一篇解决一个明确问题。

Python 字符串中输出字面花括号:format 用 {{ }} 转义;f-string 用 {{ }} 转义。本文介绍各种格式化方式中的花括号转义。

Python 美化打印 JSON:json.dumps(data, indent=4, ensure_ascii=False)。indent 控制缩进,ensure_ascii=False 保留中文。本文介绍完整用法。

Python 输出到 stderr:print(..., file=sys.stderr) 最简洁,sys.stderr.write() 更底层。logging 默认就输出到 stderr。本文介绍各种方式。

Python print 不换行:设置 end 参数为空字符串 print("内容", end=""),或 end=" " 用空格分隔。默认 end="\n" 每次换行。

Logstash 处理多行日志用 multiline codec:pattern 定义新日志行的开始模式,negate=true + what=previous 把不匹配的行追加到上一条。本文给出完整配置。

Python 性能分析用内置 cProfile 模块:python -m cProfile script.py 查看各函数耗时和调用次数。line_profiler 逐行分析。本文介绍各种工具。

Python 手动抛出异常用 raise 语句:raise ValueError("错误信息")。可抛出内置异常或自定义异常,支持 raise ... from ... 链式传递。