0

I am calling the same function within itself.

base_url="www.myurl.com"
urls_1="www.myurl.com/1"
urls_2="www.myurl.com/2"
rep_1="/report1"
rep_2="/report2"

    def get_response(url, report):
      response=requests.get(url,report, headers=header)
      data=response.json()

      if (len(data))==100:
          header.update({"range":rep + str(range_from + 100) + "-" + 
          str(range_to + 100)})
          **data2=get_response(?,?)**

     else:
         return data

When I call the function inside, I want to use the same parameters that I used to call the outer function.(Only writing the function once)

This outer function gets called hundreds of times with all different parameters; sometimes it gets called within a for loop.

Thanks in advance.

1
  • What's the problem? You are probably finding RuntimeError: maximum recursion depth exceeded? The reason why should be obvious... Commented Feb 6, 2018 at 0:37

2 Answers 2

3

What you're attempting is known as recursion in computer science.

def my_function(x,y,z): 
    something = my_function(x, y, z)

However, this is going to throw you into an infinite loop. For recursion to work, you have to have a base case -- a way of stopping -- and then simplify the problem at each step. See on-line tutorials and examples of recursion.

Sign up to request clarification or add additional context in comments.

2 Comments

@Paul: Edit the code into your question; comments can't format code, which is especially important for Python.
Please follow the posting guidelines. Among other things, any code needs to be in readable format: edit it into your original question, not into a comment.
0

data2=get_response(url, report)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.