在 Python 中,我正在使用如下代码写入文本文件:
f.write(filename + type + size + modified)
当然,输出看起来真的很丑:
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
但我想对齐条目,所以它看起来像这样:
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
我的问题与这个问题类似,只是我不知道文件名会提前多久。我应该如何处理这个?