Python类,奇怪的错误

时间:2012-12-18 11:25:03

标签: python class

我有一个班级,没什么特别的,只是一个普通的班级:

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()返回两个值的元组。 这是一个curses程序。我正在使用python 3。

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

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

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

    dispatcher()

Parseargv():

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)

1 个答案:

答案 0 :(得分:0)

没有完整的代码和回溯,这是不可能的,但我对这个问题有一些猜测:

  1. ...some unrelated codd...替换的位实际上包含多个代码路径,我们看到的代码仅在某些时间执行,因此self.ymax并不总是初始化。
  2. ...code here...more code here...重新绑定self方法中的draw()名称。
  3. majTheHero重新输入了她/他的代码,而不是使用复制和粘贴,这样做无意中纠正了ymax在其中一个地方的拼写错误。
相关问题