为什么"打印"运行命令两次?

kni*_*ght 2 python

所以我有这个代码,它返回有关该文件的一系列信息.它返回两次输出,如第二个片段所示.

list = os.listdir(".")
print Style.BRIGHT + "size        info        last-accessed    last-changed     filename" + Style.RESET_ALL
for f in list:
    info = os.stat(f)
    # "  size          info        last-accessed    last-changed     filename
    print " ", info[ST_SIZE], "                                                  " + f
Run Code Online (Sandbox Code Playgroud)

并输出:

  size        info        last-accessed    last-changed     filename
  6243                                                   .bash_history
  55                                                   .bash_profile
  3                                                   .CFUserTextEncoding
  15364                                                   .DS_Store
  102                                                   .fontconfig
  105                                                   .sh_history
  102                                                   .ssh
  442                                                   .Trash
  0                                                   .Xauthority
  105                                                   console
  6688                                                   console.py
  272                                                   Desktop
  238                                                   Documents
  442                                                   Downloads
  2924                                                   Folder
  1156                                                   Library
  204                                                   Movies
  102                                                   Music
  136                                                   Pictures
  204                                                   Public
  170                                                   Sites
  3914                                                   xetch
size        info        last-accessed    last-changed     filename
  6243                                                   .bash_history
  55                                                   .bash_profile
  3                                                   .CFUserTextEncoding
  15364                                                   .DS_Store
  102                                                   .fontconfig
  105                                                   .sh_history
  102                                                   .ssh
  442                                                   .Trash
  0                                                   .Xauthority
  105                                                   console
  6688                                                   console.py
  272                                                   Desktop
  238                                                   Documents
  442                                                   Downloads
  2924                                                   Folder
  1156                                                   Library
  204                                                   Movies
  102                                                   Music
  136                                                   Pictures
  204                                                   Public
  170                                                   Sites
  3914                                                   xetch
Run Code Online (Sandbox Code Playgroud)

对不起,这是一个网格,但正如你所注意到的,它返回了两次.

NPE*_*NPE 5

您显示的代码只打印size info...一次标题.由于您看到它打印两次,这意味着整个代码块执行两次.如果没有看到更多代码,为什么会出现这种情况.