【问题标题】:How can I beautify all files using Python script or some other ways? [closed]如何使用 Python 脚本或其他方式美化所有文件? [关闭]
【发布时间】:2017-10-04 14:45:39
【问题描述】:

我有很多未缩进的 C/C++ 源文件。我想以编程方式美化它们。我怎样才能做到这一点?

【问题讨论】:

  • 您使用的是哪个 IDE? Google 是您的朋友。

标签: python c++ c scripting


【解决方案1】:

编写一个python脚本,调用像Artistic Style这样的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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-26
    • 2020-05-07
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-29
    相关资源
    最近更新 更多