• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

Python AttributeError如何解决

更新一下:
问题已解决原来 _init_应该是两个_ , 即__init__苦笑

本人刚学python,在编写一个打飞船游戏出现以下异常:
pygame 1.9.4Hello from the pygame community. https://www.pygame.org/contribute.htmlTraceback (most recent call last):  File "alien_invasion.py", line 31, in     run_game()  File "alien_invasion.py", line 12, in run_game    (ai_settings.screen_width, ai_settings.screen_height))AttributeError: 'Settings' object has no attribute 'screen_width'------------------(program exited with code: 1)请按任意键继续. . .本人通过网上重新命名和删除.pyc文件的方法均不能解决, 不知道问题出现在哪,还请大神指教
主程序:
import sysimport pygamefrom settings import Settingsdef run_game():    # 初始化pygame,设置和屏幕对象    pygame.init()    ai_settings = Settings()    screen = pygame.display.set_mode(        (ai_settings.screen_width, ai_settings.screen_height))    pygame.display.set_caption("Alien Invation")    #设置背景颜色    bg_color = (ai_settings.bg_color)    # 开始游戏主循环    while True:        # 监视键盘和鼠标事件        for event in pygame.event.get():            if event.type == pygame.QUIT:                sys.exit()        # 每次循环都重绘屏幕        screen.fill(bg_color)        # 让最近绘制的屏幕可见        pygame.display.flip()run_game()settings.py模组
#-*-coding:gbk-*-class Settings():    """存储《外星人入侵》的所有设置的类"""    def _init_(self):        """初始化游戏的设置"""        #屏幕设置        self.screen_width = 1200        self.screen_height = 667        self.bg_color = (230,230,230)

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!