NameError when using "self" in class?
Question: I have the following Python (3.2) code:

    
    
    from pygame import *
    
    class Application:
    
        def __init__(self):
            self.running = True
            self.display_surface = None
            self.size = self.width, self.height = 640, 480
    
            self.old_ticks = pygame.time.get_ticks
            self.new_ticks = None
    
            pygame.init()
                self.display_surface = pygame.display.set_mode(self.size, pygame.HWSURFACE | pygame.DOUBLEBUF)
    
        def on_event(self, event):
            if event.type == pygame.QUIT:
                self.running = False
    
        def on_loop(self):
            pass
    
        def on_render(self):
            pass
    
        def on_cleanup(self):
            pygame.quit()
    
        def regulate_time(self):
            self.new_ticks = pygame.time.get_ticks
    
            while (self.new_ticks < self.old_ticks + 1000):
                pass
    
            self.old_ticks = self.new_ticks
    
        def load_images(self):
            pass
    
        while(self.running == True):
            for event in pygame.event.get():
                self.on_event(event)
    
            self.regulate_time
            self.on_loop()
            self.on_render()
    
        self.on_cleanup()
    
        test = Application
    

I'm having a problem with the following line:

    
    
    while(self.running == True):
    

which throws me the error : `NameError: Name "self" is not defined.`

I am pretty much a python newbie and was hoping to use this time to get
started on learning python and pygame which I could then use for my college
project (two birds with one stone) and I cannot figure out why this error is
being thrown at me.


Answer: Well, the `while(self.running == True)` is _not_ in any method (`def`) so
there is no such _variable_ called `self` in scope (which is what the
`NameError` says)...

...perhaps there is some missing indentation? Although the previous `pass`
makes it look like more than this is missing: maybe `def run(self):`?

Remember, `self` is just the conventional (and proper) name given to the
_first_ parameter for a method by which the "current instance" is implicitly
passed.

Happy coding.

