1

I want to split lines into fields and print them neatly aligned. I do not know in advance how long the names are, so I can't use a fixed format like the ones given in other Stack Overflow questions.

This is the kind of output I would like to get:

Simpson, Bartholomew Homer  12345 CSEE       £25000
Jackson, Michael            15675 History    £34000
Clown, Krusty the           56746 Economics  £67000

This is the code I have written so far:

def printFormat(details):
    details = details.split()
    lastname = details[-1]
    firstnames = " ".join(details[3:-1])
    name = ", ".join([lastname, firstnames])

    ID_Subject = " ".join(details[0:2])
    money = details[2]

    print "%s,%s    %s    %s" % (lastname,firstnames,ID_Subject,money)
Michael Laszlo
  • 12,009
  • 2
  • 29
  • 47
jayoguntino
  • 133
  • 1
  • 7
  • Also [this](http://stackoverflow.com/questions/5909873/python-pretty-printing-ascii-tables) and [this](http://stackoverflow.com/questions/8356501/python-format-tabular-output). – TigerhawkT3 Aug 20 '15 at 04:07
  • [Possible answer](http://stackoverflow.com/a/26005077/5057078), is that what you want? – Brambor Aug 20 '15 at 04:10
  • no not really i dont know how to apply that logic to my code – jayoguntino Aug 20 '15 at 04:26
  • This question should be reopened. It is not a duplicate because it cannot be solved with a fixed format as the linked questions can. – Michael Laszlo Aug 20 '15 at 05:15

0 Answers0