Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function call in recursion
#1
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.
Reply
#2
Can anyone help me on this, I'm trying this since last 2 weeks but not able to get it done.
Reply
#3
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"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 792 May-02-2023, 08:40 AM
Last Post: Gribouillis
  how to call an object in another function in Maya bstout 0 2,080 Apr-05-2021, 07:12 PM
Last Post: bstout
  In this function y initially has no value, but a call to foo() gives no error. Why? Pedroski55 8 3,498 Dec-19-2020, 07:30 AM
Last Post: ndc85430
  Struggling for the past hour to define function and call it back godlyredwall 2 2,219 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  list call problem in generator function using iteration and recursive calls postta 1 1,905 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  function call at defined system time? Holon 5 3,231 Oct-06-2020, 03:58 PM
Last Post: snippsat
  How to call/read function for all elements in my list in python johnny_sav1992 1 2,080 Jul-27-2020, 04:19 PM
Last Post: buran
  Python: Call function with variabele? Ending in error. efclem 5 2,934 Apr-22-2020, 02:35 PM
Last Post: buran
  Lambda function recursion error DeadlySocks 1 2,063 Apr-13-2020, 05:09 PM
Last Post: deanhystad
  How to mock an object that is created during function call? Schlangenversteher 0 1,973 Jan-31-2020, 01:36 PM
Last Post: Schlangenversteher

Forum Jump:

User Panel Messages

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