Maximum recursion

def player_items(x):
	if x == 'item':
		print('Player\'s inventory now contains {}'.format(player_items(x)))

This is from a game I am working on and is raising the max recursion error. I don’t understand the logic.

[EDIT] fixed typo

I forgot to take Zed’s advice to email it to me first…

My guess is that it is recurs-ing because the format function is calling the function and not the variable?

1 Like

And so to conclude :slight_smile:
To call the variable you simply do this

def items(x):
    if x == 'item':
            print('{}'.format(x))
1 Like

Yes, actually you did some of this earlier, but see how player_items is called inside player_items? That will basically make a loop. It’s similar to if you make a while loop that never ends. Python then runs out of space and dies. Better languages will happily just do this forever.