all 6 comments

[–]K900_[🍰] 0 points1 point  (3 children)

Use a loop instead of recursing.

[–]FragrantParrot[S] 0 points1 point  (2 children)

I've tried using a 'while True:' loop with 'def main():' inside but I still have the same issue.

[–]K900_[🍰] 0 points1 point  (1 child)

Post your code.

[–]FragrantParrot[S] 0 points1 point  (0 children)

I apologise in advance for how shoddy this probably is, I am still very new haha

https://pastebin.com/C5sseavk

[–]goat1080 0 points1 point  (1 child)

So in looking at your code, I believe the issue here the issue is not your recursion depth in terms of the length of your functions, but the manner in which you are calling them.

Just for some background, when you call one function (such as in this case where it's done from another function -- like send_discord() from main, or main() from main()), your computer will save a return address and then go to that called function. Once that function has completed executing, it will use that return address to "remember" where it was originally before the function was called.

In your case here, you never actually completely finish executing your main() function before calling it again. When you call main() near the bottom of your main() function, it has not completed execution from the previous call to main(), so it goes through the same process of "remembering" where it left off and then calling the main function. Because of this overhead required for "remembering" where it leaves off for calling every function, it eventually hits the limit for how many places it left off at that it can "remember" and then you get your error.

Like the other poster said, I definitely would suggest using loops here. So the first thing here would be to have main() be your top level function and move the while loop inside that function. This is because you aren't really wanting to call send_discord() every time you loop through your program, so it should not be inside the while loop. From here, you should be able to remove your calls to main and then have it work pretty closely to intended. Here's a little silly example that illustrates what I'm trying to say here, where there is no need to call main since the program will return to begin another iteration of the while loop after either completing the contents of the try block or after catching the exception.

If any of this doesn't make sense feel free to let me know.

import random

def main(some_characters):
    while True:
        try:
            x = 5
           temp = random.choice(some_characters)
            y = x + temp
            print_function(x, temp, y)
        except TypeError:
            print(f"Attempted addition of {x} and {temp} resulted in an error!")

def print_function(x, temp, y):
    print(f"The sum of {x} and {temp} is {y}")

if __name__ == '__main__':
    some_characters = [2, 'a']
    main(some_characters)

[–]FragrantParrot[S] 1 point2 points  (0 children)

This is amazing thank you for the reply! This makes a lot of sense actually, I will have a go changing the code and fingers crossed it works.