-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() は、2 つの値のタプルを返します。これは呪いのプログラムです。私はpython3を使用しています。

編集 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)
4

1 に答える 1

0

完全なコードとトレースバックがないと判断できませんが、問題についていくつか推測できます。

  1. 置き換えられたビットには...some unrelated codd...実際には複数のコード パスが含まれており、表示されるコードは時々実行されるだけなので、self.ymax常に初期化されるとは限りません。
  2. ...code hereまたはメソッド内で...more code here...名前を再バインドします。selfdraw()
  3. majTheHero は、コピー アンド ペーストを使用する代わりに自分のコードを再入力し、ymax使用されている場所の 1 つにある のスペルミスを誤って修正しました。
于 2012-12-18T13:38:10.283 に答える