簡體   English   中英

python模塊沒有屬性

[英]python module has no attribute

AttributeError: module 'actions' has no attribute 'MoveEast' 在終端中不斷彈出。 我嘗試重命名函數並執行不同的導入方法,例如

from actions import Actions

但什么也沒有發生。

import items, enemies, dungeon, player, actions
#rooms.py
#function in question
def adjacent_moves(self):
    moves = []
    if dungeon.room_exists(self.x + 1, self.y):
        moves.append(actions.MoveEast())
    if dungeon.room_exists(self.x - 1, self.y):
        moves.append(actions.MoveWest())
    if dungeon.room_exists(self.x, self.y - 1):
        moves.append(actions.MoveNorth())
    if dungeon.room_exists(self.x, self.y + 1):
        moves.append(actions.MoveSouth())
    return moves

#actions.py
class Actions:
    def __init__(self, method, name, hotkey, **kwargs):
        self.method = method
        self.hotkey = hotkey
        self.name - name
        self.kwargs = kwargs

def MoveEast(Actions):
    def __init__(self):
        super().__init__(method=Player.move_right, name="Move Right", hotkey="r")

#from player.py
def move(self, dx, dy):
    self.location_x += dx
    self.location_y += dy
    print(dungeon.room_exists(self.location_x, self.location_y).intro_text())

def move_right(self):
    self.move(dx= 1, dy= 0)

改變

def MoveEast(Actions):
    def __init__(self):
        super().__init__(method=Player.move_right, name="Move Right", hotkey="r")

class MoveEast(Actions):
    def __init__(self):
        super().__init__(method=Player.move_right, name="Move Right", hotkey="r")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM