gpt4 book ai didi

python - 为什么 "print"会运行两次命令?

转载 作者:行者123 更新时间:2023-11-28 22:00:50 24 4
gpt4 key购买 nike

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

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

输出:

  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

很抱歉,它是一个网格,但正如您所注意到的,它返回了两次。

最佳答案

您显示的代码只打印一次 size info... header 。由于您看到它被打印了两次,这意味着整个代码块被执行了两次。如果不查看更多代码,就无法判断为什么会出现这种情况。

关于python - 为什么 "print"会运行两次命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14135773/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com