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

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()

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 ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.