Python Docx 添加简单数学方程的输出

Python Docx add output of simple math equation

如何将简单数学方程式的输出添加到我的 docx 文档中?

例如

math = 2+2

math

add_paragraph 只能做字符串,不能做整数。有解决办法吗?

p = document.add_paragraph(math)
document.save('doc.docx')

使用转换

math_string = str(math)
p = document.add_paragraph(math_string)
document.save('doc.docx')

可以将 int 转换为字符串吗?

p = document.add_paragraph(str(math))