how to format printing in PYTHON without object length -


so have data i'm trying print file within columns.

this current formatting:

print_to_file = open('best_and_worst.txt', "w")  print("category {:>25s} best {:>25s} worst".format('',''), file=print_to_file)  print("heart disease:{0:21s}".format(best_hd_state), file = print_to_file) 

what want print spaces distance category (in case "heart disease:") until it's aligned "best", print 1 space , value , after print spaces until aligned "worst" print state, space, , value.

the problem encounter don't know how deal varying length of objects , further don't know how have variable formatting. (i.e. adjusting number of spaces according length of object , distance between , next column want align with.) whole point of program organize state data csv file , print information new file. can't use single value while formatting because if state data changes things fall out of line. please halp.


Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -