私は次のPython(3.2)コード持っている:私はNameError: Name "self" is not defined.
クラスで "self"を使用している場合のNameError?
:
while(self.running == True):
私にエラーがスローされます:私は次の行に問題を抱えている
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
を私が大学のプロジェクト(1つの石で2羽の鳥)に使うことができるPythonとPygameを学ぶためにこの時間を使うことを望んでいたので、なぜこのエラーが私に投げられているのか分かりません。
[Pythonスタイルガイド、PEP 8、](http://www.python.org/dev/peps/pep-0008/#id39)は 'if(b == True): '悪い形です。代わりに 'if(b)'を使ってください。 –
私の最初の言語はC++ですので、私を許してください!私は未来のためにPythonのスタイルを心に留めようとします:P –
Pythonを初めて使う人はDavid Goodgerの["Idiomatic Python"を読んでください。](http://python.net/~goodger/projects /pycon/2007/idiomatic/handout.html)それは驚くほどの数の 'aha!'を含んでいます。あなたが考えることのない瞬間と素敵なトリックです。 –