Python Forum
Recursive Call Going Elsewhere?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursive Call Going Elsewhere?
#1
I have some python code outside of a function that walks a directory tree. When the code detects a zip file (which could be nested), it calls a method called "ProcessZipFile(filePath)".

Inside that recursive function, if another zip file is found, it calls itself to process.

Here's the recursive function:

# process zip files recursively if necessary
def processZipFile(filePath):
    file = zipfile.ZipFile(filePath, "r")
    for name in file.namelist():
        data = file.read(name)
        print(name)  # of file
        if (str(name).endswith(".zip")):
            processZipFile(name)
The strange thing is that when the code hits the lower processZipFile(name) line of code in the method above, instead of going back to the top and recursively processing, the code goes to the original call in the code that called this function.

main code below (not in a function):
.
.
.
  if (filePath.endswith("zip")):
            processZipFile(filePath)
I'm still new to Python, but I don't see what's going on. Why isn't the recursive call going back to the top of the function?

The recursive method does process the first zip file correctly.

Hope this posting is clear.

Thanks in advance,
Reply


Messages In This Thread
Recursive Call Going Elsewhere? - by Oliver - Jan-30-2018, 09:51 PM
RE: Recursive Call Going Elsewhere? - by Oliver - Jan-31-2018, 01:33 PM
RE: Recursive Call Going Elsewhere? - by snippsat - Jan-31-2018, 02:44 PM
RE: Recursive Call Going Elsewhere? - by DeaD_EyE - Jan-31-2018, 02:59 PM
RE: Recursive Call Going Elsewhere? - by Oliver - Jan-31-2018, 09:42 PM
RE: Recursive Call Going Elsewhere? - by DeaD_EyE - Feb-02-2018, 09:58 AM
RE: Recursive Call Going Elsewhere? - by Oliver - Feb-02-2018, 10:58 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 7,505 Jan-17-2021, 03:02 AM
Last Post: Jeremy7
  list call problem in generator function using iteration and recursive calls postta 1 1,945 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  how to get around recursive method call Skaperen 10 4,350 Jul-01-2020, 10:09 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020