How To Use Recursion In Python
Вставка
- Опубліковано 28 вер 2024
- In this video I go over how to use recursion in the Python Programming Language. Recursion allows us to call functions within themselves. This is useful when searching through file trees.
Straighr to the point and well explained.
Love your videos buddy! Thx so much
I'm glad! Thank you very much! :)
bro speaks in 0.75x speed (nice tutorial tho)
Thanks for a great video. I keep all my code on an external drive. The file is 5 folders down from the root dir. but when I rune the code the print(fd) I get H://Python Code. The file is in H://Python Code/Test File 1/Test File 2/Test file 3/Test File 4/ Recursion In Python.py In the loop it does not get True from if (fd == ""): To then run print("recursion stopped") and then return. Here is my code.
import os
def rec(fd):
if (fd == ""):
print("recursion stopped")
return
else:
print(fd)
FormatDirectory = fd.rsplit("/", 1)
print(os.listdir(fd))
rec(FormatDirectory[0])
if __name__ == "__main__":
fullDirectory = os.getcwd()
rec(fullDirectory)
I think you're using Windows, the file structure is a little different. Without seeing the error, I believe all you need to do is change the if statement from if (fd == "") to if (fd == "H:/"). I hope this helps!
@@TaylorsSoftware it did and thank you!!
I really appreciated that you maximised the size of the text in your presentation. Zooming in makes it so much easier to follow along with.
what about memory usage with this option?
agree... good video
Well done, good teaching style
Thank you so much! :)
Very useful, many thanks!
Thank you! :)