AttributeError:'module'对象没有属性???我迷路了

时间:2014-09-24 00:57:05

标签: python class exception import module

好的,我的模块中的代码名为Enemy.py:

from livewires import games, color
import random
import Cans



class Chef(games.Sprite):

    def __init__(self,pic,y = 55, speed = 2, odds_change = 200):
        super(Chef, self).__init__(image = pic,
                                   x = games.screen.width / 2,
                                   y = y,
                                   dx = speed)
        self.odds_change = odds_change
        self.time_til_drop = 0
        self.pizza = []
        self.i = 0

现在我的主程序名为TheGame.py,我有这段代码:

from livewires import games, color
import random
import PersonPlayer
import Cans
import Enemy

games.init(screen_width = 1280, screen_height = 720, fps = 50)
games.music.load("Sound/NowWeDance.mp3")
wall_image = games.load_image("lacrosse.jpg", transparent = False)
games.mouse.is_visible = False
games.screen.event_grab = True
chefimg = games.load_image("Sprites/chef.bmp")
manlhimg = games.load_image("Sprites/manlh.bmp")




def main():

    games.music.play()
    games.screen.background = wall_image
    the_chef = Enemy.Chef(chefimg)
    games.screen.add(the_chef)

    the_hand = Hand(the_chef)
    games.screen.add(the_hand)

    games.screen.mainloop()



main()

当我尝试运行它时,我收到此错误(以及其他类似的错误来自其他导入的类):

     File "C:\Users\Admin\workspace\Catcher\src\TheGame.py", line 28, in main
  the_chef = Enemy.Chef(chefimg)
AttributeError: 'module' object has no attribute 'Chef'

我的Enemy模块确实具有Chef属性,我完全混淆了为什么我会收到此错误,有人请求帮助!

0 个答案:

没有答案