Home:ALL Converter>Library for converting python string to c style code

Library for converting python string to c style code

Ask Time:2021-07-08T13:33:45         Author:harry

Json Formatter

need help with styling.

c_code = """
//This is an auto-generated file, please don't edit.
#include <stdio.h>
int main(){
return 0;
}
"""
file = open('main.c', 'w')
file.write(c_code)
file.close()

I have this simple code that will generate a c file from a python string. Is there a way to write the code after formatting in c style to the file? Instead of me explicitly indenting all code in the string?

So instead of this:

    //This is an auto-generated file, please don't edit.
    #include <stdio.h>
    int main(){
    return 0;
    }

I need this:

//This is an auto-generated file, please don't edit.
#include <stdio.h>
int main() {
    return 0;
}

Is there a library that can do this? Thanks in advance.

Author:harry,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/68296136/library-for-converting-python-string-to-c-style-code
yy