Categories
Mastering Development

Prython print format

I start with a list tbe_fmt. having trouble formatting the write to file.
Trouble in left justify. Perhaps better way.

tbe_fmt = []
for i,j,k in zip(idx_tbe, inn_dia, out_dia):
    tbe_fmt.append(str(inn_dia[i])+' x '+str(out_dia[i]))

>>> tbe_fmt  = ['1.63 x 1.91', '2.09 x 2.38', 
>>>             '2.50 x 2.88', '3.10 x 3.50', 
>>>             '4.06 x 4.50']

tbe_str = ''
for i in tbe_fmt:
    tbe_str += i+','+' '
tbe_str = tbe_str.strip()
tbe_str = tbe_str[:-1]
tbe_str = '['+tbe_str+']'

ins_tbe_fmt = 'ins_tbe_fmt = '
tbe_str = tbe_str.replace(',', ','+'\\'+'\n')
tbe_str = tbe_str.ljust(len(ins_tbe_fmt))

desired output is:
ins_tbe_fmt = [1.63 x 1.91,\
               2.09 x 2.38,\
               2.50 x 2.88,\
               3.10 x 3.50,\
               4.06 x 4.50]

Leave a Reply

Your email address will not be published. Required fields are marked *