In my piece of code, I have,
out.write(datGroup)
out.write(' '*20+": Space Group\n")
out.write(datLatx +" ")
out.write(datLaty +" ")
out.write(datLatz +" ")
out.write('/'),
out.write(' '*20+": a,b,c,alpha,beta,gamma\n")
which gives the output as:
189 : Space Group
10 11 12 / : a,b,c,alpha,beta,gamma
which is correct for what I have done, but not what I have want.
I want the ": Spacegroup" and ": a,b,c.." to start from the same column, irresepective of where the data of its row ended, like:
189 : Space Group
10 11 12 / : a,b,c,alpha,beta,gamma
Can I do that in python3?
EDIT after jonrsharpe's example So I have tried:
def write_row(out, data, header, col=20):
out.write("{0}: {1}".format(" ".join(map(str, data)).ljust(col), header))
def print_data(self, BSub):
.....
with open("Init", mode='w') as out:
write_row(out, (datGroup,), "Space Group")
which is giving error:
$ python3 geninit.py
Traceback (most recent call last):
File "geninit.py", line 109, in print_data
write_row(out, (datGroup,), "Space Group")
NameError: global name 'write_row' is not defined
'{}'.format