0

Let's say I have this:

class main:
     def add(self):
          print '1 + 2 = 3'

I then want to be able to call the add function again from within itself. Like this (BUT THIS DOESNT WORK!!!)

class main:
     def add(self):
          print '1 + 2 = 3'
          self.add()

I've tried using other classes all looped round...but that doesnt work either... :(

This should be simple but I have forgotten :(

Thanks
Mark

2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by SgtMe
0

This works, but you will exceed the maximum recursion depth quickly ...

class Main:
    def add(self):
        print '1 + 2 = 3'
        self.add()

main = Main()
main.add()
0

I reached the recursion depth thingy near instantly (above code is example!), but I've managed to get round it. Thanks anyway.

PS.
Nice pic vegaseat ;)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.