how to aligned column with respect to longest Row(book name) of a file in python

Viewed 23

i am writing a python program which save the book name date of publication and edition in a file i want all the column vertically align(date of publication and edition) with respect to longest book name. i have used the python format function but the issue is that i have sevral file so i do not want to change my format function for each file is there any option in python which can allign them by it self.
below is the example and also expected output
ABSALOM, ABSALOM! BY WILLIAM FAULKNER     1936   1
A TIME TO KILL BY JOHN GRISHAM                      1989   3
THE HOUSE OF MIRTH BY EDITH WHARTON        1905   7
as you can see here all the column are vertically allign with respect to longest book name i.e row of a file.
below is my code which i use for it i.e format function.
note: here these data i am taking from my dictionary "el"
note: i do not want to import any library.

    file_line2 = "{:79}".format(el.get("book_name"))+ "{:15}".format(el.get("publication_date"))+  
   "{:>3}\n".format(el.get("edition"))
    text_file.write(file_line2) #writing above code in my text_file

the above function is working fine only one which it is called but as i mention i have sevral files and sevral books so can any help me with that thank you.

0 Answers
Related