Note: maybe you should determine length of "longest" fname and lname,
say max_fname and then format the the fname column in max_fname+1 spaces
Similarly for lname
col1: max_fname + 1
col2: max_lname + 1
col3: 18 + 1 = 19
col4: 9 + 1 = 10
col5: 19
col6: 10
col7: 8
january
february
march
april
may
june
july
august
september 9
october
november
december
print("{:(max_fname+1)s}{:(max_fname+1)s}{:19s}{:10s}{:19s}{:10s}{:8d}".format(a,b,c,d,e,f,g))
a = "Srinivasa"
b = "Ramanujan"
c = "22 December, 1887"
d = "Thursday"
e = "26 April, 1920"
f = "Monday"
g = 11813
max_fname = 9
max_lname = 11
print("{:10s}{:12s}{:19s}{:10s}{:19s}{:10s}{:8d}".format(a,b,c,d,e,f,g))
Srinivasa Ramanujan 22 December, 1887 Thursday 26 April, 1920 Monday 11813
print(f"%{max_fname}s %{max_lname}s %18s %9s %18s %9s %8d" % (a,b,c,d,e,f,g))
Srinivasa Ramanujan 22 December, 1887 Thursday 26 April, 1920 Monday 11813
print(a,end="")
print(" "*(max_fname + 1 - len(a)),end="")
print(b,end="")
print(" "*(max_lname + 1 - len(b)),end="")
print("{:19s}{:10s}{:19s}{:10s}{:8d}".format(c,d,e,f,g))
Srinivasa Ramanujan 22 December, 1887 Thursday 26 April, 1920 Monday 11813
"aa"*5
'aaaaaaaaaa'
print(f'%{max_fname}s %{max_lname}s %18s %9s %18s %9s %8d' % (a,b,c,d,e,f,g))
Srinivasa Ramanujan 22 December, 1887 Thursday 26 April, 1920 Monday 11813
class Date:
# Constructor
def __init__(self, m, d, y):
self.month = m
self.day = d
self.year = y
def __str__(self):
return str(self.month)
fname = "p1.dat"
with open(fname) as f:
data = f.read().splitlines()
celebrities = []
for d in data: # d = 'Albert:Einstein:3/14/1879:4/18/1955'
xs = d.split(":") # xs = ['Albert','Einstein','3/14/1879','4/18/1955']
ys = xs[2].split("/") # ys = ['3','14','1879']
dob = Date(int(ys[0]),int(ys[1]),int(ys[2]))
if xs[3] == "":
dod = None
else:
ys = xs[3].split("/") # ys = ['4','18','1955']
dod = Date(int(ys[0]),int(ys[1]),int(ys[2]))
celebrities.append((xs[0],xs[1],dob,dod))
# return celebrities
for celebrity in celebrities:
print(celebrity[0],celebrity[1],str(celebrity[2]),str(celebrity[3]))
Albert Einstein 3 4 Donald Knuth 1 None Srinivasa Ramanujan 12 4 Isaac Newton 12 3 Tim Berners-Lee 6 None Alonzo Church 8 6 Alan Turing 6 6 Leonhard Euler 4 9 Jimi Hendrix 11 9 Bob Marley 2 5