如何使用Python脚本或其他方式美化所有文件?

2024-04-24 22:13:52 发布

您现在位置:Python中文网/ 问答频道 /正文

<>我有很多未编码的C/C++源文件。我想以编程方式美化它们。我怎样才能做到这一点?你知道吗


Tags: 编码编程方式源文件
1条回答
网友
1楼 · 发布于 2024-04-24 22:13:52

编写一个Python脚本,调用C++美化器,如艺术风格。你知道吗

http://astyle.sourceforge.net/

下面是python脚本的外观:

# Collect all the files you need to beautify in "files"

#Loop through each C/C++ file
for file in files:
    command = "astyle " + file
    import subprocess
    process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
    output, error = process.communicate()

艺术风格的使用举例如下:

astyle example.cpp

或者

astyle  style=ansi  indent=tab example.cpp

相关问题 更多 >