python table view output
<p>I have some thing like this in output.txt file</p>

<pre><code>Service1:Aborted
Service2:failed
Service3:failed
Service4:Aborted
Service5:failed
</code></pre>

<p>output in 2nd file(output2.txt) :</p>

<pre><code> Service1        Service2   Servive3   Service4     Service5
 Aborted         failed     failed     Aborted      failed
</code></pre>

<p>Would like to get output in table format as above</p>

<p>Code I am trying:</p>

<pre><code>    file=open('output.txt','r')
    target=open('output2.txt','w')
    states=[]
    for line in file.readlines():
         parts=line.strip().split(':')
         states.append(parts[1].strip())
   target.write(','.join(states))        
   target.close()
</code></pre>

<p>Very quickly:</p>

<pre><code>headers = []
statuses = []

for line in file:
    line=line.strip()
    parts=line.split(":")
    headers.append(parts[0])
    statuses.append(parts[1])

format_str = '{:&gt;15}'*(len(headers))

print(format_str.format(*headers))
print(format_str.format(*statuses))
</code></pre>

python python-2.7 python-3.x