linux - Python output streamline in table with print command -


in python script reading command output , putting them in loop extract specific column, trying format output looks little cluttered if few character more in result. how make them nice look?

for in data:             print i[2], '|', i[12], '\t|', i[9], '\t\t\t|', i[24].split('@')[-1] 

output:

[root@tux work]# ./foo.py 2015-04-24 10:26:44 | ringing   | 17654742161                   | 2015-04-24 10:26:44 | ringing   | 00100017654742161                     | 2015-04-24 10:13:52 | active    | 18146252950                   | 72.xx.xx.120 2015-04-24 10:24:25 | active    | 17323576331                   | 72.xx.xx.120 

i want out put following

[root@tux work]# ./foo.py     2015-04-24 10:26:44 | ringing   | 17654742161                   |     2015-04-24 10:26:44 | ringing   | 00100017654742161             |     2015-04-24 10:13:52 | active    | 18146252950                   | 72.xx.xx.120     2015-04-24 10:24:25 | active    | 17323576331                   | 72.xx.xx.120 

one way use string formatting. according samples, can this:

for in data:     params = [i[2], i[12], i[9], i[24].split('@')[-1]]     print '{:20s} | {:10s} | {:20s} | {:16s}'.format(*params) 

as commented @twalberg, can read more here


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -