1
在util.pyPython的導入類堆棧
class Stack:
"A container with a last-in-first-out (LIFO) queuing policy."
def __init__(self):
self.list = []
def push(self,item):
"Push 'item' onto the stack"
self.list.append(item)
def pop(self):
"Pop the most recently pushed item from the stack"
return self.list.pop()
def isEmpty(self):
"Returns true if the stack is empty"
return len(self.list) == 0
在game.py
class Directions:
NORTH = 'North'
SOUTH = 'South'
EAST = 'East'
WEST = 'West'
STOP = 'Stop'
LEFT = {NORTH: WEST,
SOUTH: EAST,
EAST: NORTH,
WEST: SOUTH,
STOP: STOP}
RIGHT = dict([(y,x) for x, y in LEFT.items()])
REVERSE = {NORTH: SOUTH,
SOUTH: NORTH,
EAST: WEST,
WEST: EAST,
STOP: STOP}
在search.py
from game import Directions
s = Directions.SOUTH
w = Directions.WEST
e = Directions.EAST
n = Directions.NORTH
from util import Stack
stack = Stack
stack.push(w)
我得到stack.push錯誤(W)說:「TypeError:必須使用堆棧實例調用未綁定的方法push()作爲第一個參數(而不是str實例)」
這到底意味着什麼?我不能推w? 如果是這樣,我能做些什麼將w推入堆棧?
被替換啊,謝謝你非常。新的python。它現在有效。 – ealeon