If you use Python3, you can apply formatting this way ...
# needs Python3
data_list = [
(1, 'Dave'),
(234, 'Einstein'),
(100000, 'Bob')
]
print("Printing out to file 'test123.txt' ...")
fout = open("test123.txt", "w")
for item in data_list:
sf = "{0:>10d} {1:30}"
# show on the screen as a test
print(sf.format(item[0], item[1]))
# redirect print() to a file
print(sf.format(item[0], item[1]), file=fout)
fout.close()
With older versions of Python you can use the % formatting directive, similar to the one used in the C language.
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417