Python类,strang

2024-10-05 14:23:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一节课,没什么特别的,只是一节普通课:

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...

当我尝试访问“自身.ymax“在while循环中,我得到一个错误,说classs窗口没有atribute ymax。 我做错什么了???你知道吗

编辑: getmaxyx()返回两个值的元组。 这是一个诅咒程序。我用的是python3。你知道吗

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

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)

Tags: selfheredefcodewindowwininterfaceymax
1条回答
网友
1楼 · 发布于 2024-10-05 14:23:38

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

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

相关问题 更多 >