python - IndentationError 但它没有混淆制表符和空格
问题描述
当我尝试运行我的脚本时,它坚持认为第 10 行有一个 IndentationError,即 def init (self): 行。查找它我尝试了一些我见过的常见修复,检查以确保选项卡和空格没有混淆,确保循环结构正确,但没有任何工作!
import sys
import pygame
from settings import Settings
from ship import Ship
class AlienInvasion:
"""Overall game assets and behavior"""
def __init__(self):
"""Initialize the game, and create game resources"""
pygame.init()
self.settings = Settings()pi
self.screen = pygame.display.set_mode((self.settings.screen_width, self.settings.screen_height))
pygame.display.set_caption("Alien Invasion")
self.ship = Ship(self)
# Set the background
self.bg_color = (230, 230, 230)
def run_game(self):
"""Start the main loop for the game"""
while True:
# Watch for keyboard and mouse events.
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
# Redraw the screen during each pass through the pass
self.screen.fill(self.settings.bg_color)
self.ship.blitme()
# Make the most recently drawn screen visible
pygame.display.flip()
if __name__ == '__main__':
# Make a game instance, and run the game
ai = AlienInvasion()
ai.run_game()
如果有人能告诉我发生了什么,那将不胜感激。在我的编码生涯中这么晚才尝试 Python 实在是太棒了。
解决方案
这个:
class AlienInvasion:
"""Overall game assets and behavior"""
应该是这样的:
class AlienInvasion:
"""Overall game assets and behavior"""
使其匹配下一个定义:
def __init__(self):
推荐阅读
- gradle - 使用 Kotlin 实现插件时如何为 Gradle 扩展任务?
- python - json文件中布尔数据类型的反序列化在python中不起作用
- c++ - 将 lambda 传递给可变参数 std::function 时的类型推导
- laravel - 在运行时在集合上添加属性追加
- android - 签名的 React Native 应用程序未正确加载资产
- android - React-Native:如何使用模糊创建 UI
- botframework - Microsoft 签名密钥不再有背书
- wordpress - 我的 .htaccess 文件与通过 Filezilla 上传的 301 重定向给出 500 内部服务器错误有什么问题?
- excel - 宏提示我选择文件,即使它打开
- c# - 没有外键的实体框架主从数据输入