-1

我有一堂课,没什么特别的,就是一堂普通的课:

class WINDOW ():
    def __init__ (self, path):
        ...some unrelated codd...
        self.win = newwin(stdscr.win.getmaxyx() [0]-2, stdscr.win.getmaxyx() [1], 0, 0)
        self.xmax = self.win.getmaxyx() [1]
        self.ymax = self.win.getmaxyx() [0]

    def draw(self,flin,fcol):
        ...code here
        i = 0
        while i < self.ymax -1:
            ...more code here...

当我尝试在 while 循环中访问“self.ymax”时,出现错误,说类 WINDOW 没有 ymax 属性。我做错了什么???

编辑: getmaxyx() 返回两个值的元组。这是一个诅咒程序。我正在使用python 3。

编辑 2:更多代码 - 创建 WINDOW 的实例:

def main():
    global stdscr
    stdscr = initscr()
    global interface

    interface = INTERFACE(stdscr)
    interface.wins.append(WINDOW(parseArgv()))

    dispatcher()

解析器():

def parseArgv():
    #arguments are [filename, PathToFileThatThisProgramOpens]
    if len(argv) == 1:
        return None
    else:
        return argv[-1]

调用draw():

def SwitchWindow(self):
    self.wins[self.currentWindow].empty()
    self.currentWindow += 1 #select next window
    line = self.wins[self.currentWindow].flin
    coll = self.wins[self.currentWindow].fcol
    self.wins[self.currentWindow].draw(line,coll)
4

1 回答 1

0

如果没有完整的代码和回溯,就无法判断,但我对这个问题有一些猜测:

  1. 被替换的位...some unrelated codd...实际上包含多个代码路径,并且我们看到的代码仅在某些时候执行,因此self.ymax并不总是被初始化。
  2. 要么 要么...code here重新绑定方法中...more code here...的名称。selfdraw()
  3. majTheHero 重新输入了她/他的代码,而不是使用复制和粘贴,这样做无意中更正了ymax其中一个使用位置的拼写错误。
于 2012-12-18T13:38:10.283 回答