0

I have a list of tuples myTuple = (string1,integer,string2,string3) that I want to print to a file, with only the second string left justified.

I can form the following string:

myString = '%4s  %5i  %3s %3s\n' % myTuple

which I then print to a file

f.write(myString)

string2 can be 1,2, or 3 characters long. So for various combinations I get the following format:

XXXX      1    X XXX
XXXX      2   XX XXX
XXXX      3  XXX XXX

What I want to have instead is

XXXX      1  X   XXX
XXXX      2  XX  XXX
XXXX      3  XXX XXX

Is it possible to left-justify the second string?

sodiumnitrate
  • 2,899
  • 6
  • 30
  • 49

0 Answers0