Python Forum
function call in recursion - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: function call in recursion (/thread-16162.html)



function call in recursion - moong - Feb-16-2019

Basically I need to call the function recursively.
Below is my code

path="/home/"
url = "<url>"
nme = {'xmlns' : url}
def find( repo, dep ):
    pom=path+repo+"/pom.xml"
    if not os.path.exists(pom):
        return
    tree = ElementTree.parse(pom)

    root = tree.getroot()
    deps = root.findall(".//xmlns:dependent", nme=nme)
    for d in deps:
        aid = d.find("xmlns:aid", nme=nme)
        vsn    = d.find("xmlns:vsn", nme=nme)
        if dep == aid.text:
            print repo + " : " + vsn.text
            file_change(repo)
    return
print "\ndependecy:\n"
rps=os.walk(path).next()[1]
for repo in rps:
    find(repo, dep)
print "\n"
when I run the above script by passing parameter as util, It gives the output as drive, exporter, handler and so on and I am calling file_change function in each iteration to update the xml file

so here I need to call the same function by passing the input as drive and then next exporter and so on.

if drive or exporter and so on gives output as anyother repos, then we need to run the same function for that repos as well until we get nothing.

the above code fits for only one iteration but it doesn't fit for recursion. How can I implement recursion call in the above code.


RE: function call in recursion - moong - Feb-17-2019

Can anyone help me on this, I'm trying this since last 2 weeks but not able to get it done.


RE: function call in recursion - moong - Feb-17-2019

Since I have not received any response. I tried in the below way. The code looks good to me but it is running into infinite loop in the for loop is for repo_temp in rps_temp: so the function call running into infinite loop. where I am making mistake in the below code.

path="/home/"
url = "<url>"
nme = {'xmlns' : url}
def find( repo, dep ):
    pom=path+repo+"/pom.xml"
    if not os.path.exists(pom):
        return
    tree = ElementTree.parse(pom)
 
    root = tree.getroot()
    deps = root.findall(".//xmlns:dependent", nme=nme)
    for d in deps:
        aid = d.find("xmlns:aid", nme=nme)
        vsn    = d.find("xmlns:vsn", nme=nme)
        if dep == aid.text:
            print repo + " : " + vsn.text
            rps_temp=os.walk(path).next()[1]
            temp = repo
            for repo_temp in rps_temp:
                dep_check(repo_temp, temp)
    return
print "\ndependecy:\n"
rps=os.walk(path).next()[1]
for repo in rps:
    find(repo, dep)
print "\n"