Align columns in a text file

前端 未结 3 1428
北海茫月
北海茫月 2021-02-05 10:03

I am a Python noobie and I\'m stuck on something I know is going to be simple...

I have a plain text file that contains user login data:

dtrapani  HCPD-E         


        
3条回答
  •  旧巷少年郎
    2021-02-05 10:51

    str.ljust(width, [fillchar=" "]) (http://docs.python.org/2/library/stdtypes.html#str.ljust) seems like what you're after. Left justify each field when printing to the maximum length + a little bit.

    For the last field to match your example, you'll want to right justify it instead using rjust.

提交回复
热议问题