0

For example, I need to generate cpp code with python.

Let's assume

int x;
double y;

Note: it can be other types.

How can I generate equal spaces ?

I want to get:

int    x;

double y;
petezurich
  • 9,280
  • 9
  • 43
  • 57
Alex
  • 41
  • 5
  • Your question is not clear. How do you propose to generate C++ code with Python? Have you tried something? Are you not getting equal spaces? Please share current output and expected output. – amanb Apr 14 '19 at 14:56
  • Side-note: C++ doesn't care about spacing, and most style guides would reject spacing like this, so why bother? – ShadowRanger Apr 14 '19 at 15:00

1 Answers1

0

Use str formating:

>>> "{:<10}{};".format("int", "x")
'int       x;'
>>> "{:<10}{};".format("double", "y")
'double    y;'
Netwave
  • 40,134
  • 6
  • 50
  • 93