如何缩进多行字符串的内容?

如何缩进多行字符串的内容?

问题描述:

我正在使用python cog 模块生成C ++样板代码,并且运行良好,因此到目前为止,但我唯一担心的是,由于代码本身没有缩进,因此导致代码本身很丑陋,因此变得更糟.我懒得在字符串生成函数中获得缩进,所以我想知道是否有Python util函数来缩进多行字符串的内容?

I'm using the python cog module to generate C++ boilerplate code, and it is working great so far, but my only concern is that the resulting code, which is ugly by itself, is made worse by the fact that it's not indented. I'm too lazy to get the indentation right in the string generation function, so I'm wondering if there is a Python util function to indent the content of a multi-line string?

为什么不通过诸如astyle之类的命令行代码格式化程序通过管道传递输出?

Why not pipe the output through a command-line code formatter such as astyle?