Yield in a recursive function

后端 未结 9 503
独厮守ぢ
独厮守ぢ 2021-01-30 10:49

I am trying to do something to all the files under a given path. I don\'t want to collect all the file names beforehand then do something with them, so I tried this:

<         


        
9条回答
  •  -上瘾入骨i
    2021-01-30 11:06

    os.walk is great if you need to traverse all the folders and subfolders. If you don't need that, it's like using an elephant gun to kill a fly.

    However, for this specific case, os.walk could be a better approach.

提交回复
热议问题