Skip to content
Advertisement

print/list only 5 entries from OS.Walk in python

My Goal – To list only 5 entries when using OS walk. So far I have only been able to get a list of everything that I find using OS.Walk or only list one entry. (By using the return function)

My code: import os import subprocess

JavaScript

The Results:

JavaScript

My code

If there is any way to only show 5 instead of the whole list that would be great! I tried using len() but I was having trouble figuring out how to use it with the os walk search. I would say the biggest thing is the music=str(os.path.join(root,file)) as that does the search I believe.

Any ideas would be appreciated. Thank you for your time,

Advertisement

Answer

Try this:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement