title: Writing nicely formatted text in Python
body: <p>In Python, I'm writing to a text file with code like:</p>
  
  <pre><code>f.write(filename + type + size + modified)
  </code></pre>
  
  <p>And of course the output looks really ugly:</p>
  
  <pre><code>C:/Config/ControlSet/__db.006  file          56 KB   2012-Apr-30 10:00:46.467 AM
  C:/Config/ControlSet dir       68881 KB   2012-Apr-30 10:00:46.396 AM 
  C:/Config/DataStore.avlocate file           0 KB   2012-Apr-30 09:57:42.440 AM 
  C:/Config/DataStoreLocate.bak file           0 KB   2012-Apr-30 09:57:42.470 AM 
  C:/Config/DeviceConnections/devconn.bak file          41 KB   2012-Apr-30 10:39:50.181 AM   
  C:/Config/DeviceConnections/devconn.cfg file          41 KB   2012-May-29 10:12:45.288 AM
  </code></pre>
  
  <p>But I want to align the entries so it looks like this:</p>
  
  <pre><code>C:/Config/ControlSet/__db.006                                            file          56 KB   2012-Apr-30 10:00:46.467 AM
  C:/Config/ControlSet                                                      dir       68881 KB   2012-Apr-30 10:00:46.396 AM 
  C:/Config/DataStore.avlocate                                             file           0 KB   2012-Apr-30 09:57:42.440 AM 
  C:/Config/DataStoreLocate.bak                                            file           0 KB   2012-Apr-30 09:57:42.470 AM 
  C:/Config/DeviceConnections/devconn.bak                                  file          41 KB   2012-Apr-30 10:39:50.181 AM   
  C:/Config/DeviceConnections/devconn.cfg                                  file          41 KB   2012-May-29 10:12:45.288 AM
  </code></pre>
  
  <p>My issue is similar to <a href="https://stackoverflow.com/questions/2866637/nicely-formatted-text-file">this question</a> except I don't know how long the filenames will be beforehand. How should I approach this?</p>