1

私は、python 用の curses のクロスプラットフォーム モジュールである Unicurses で作業していました。「@」文字をコンソールの中央に配置しようとしていました。私のコードはこれでした:

from unicurses import *
def main():
    stdscr = initscr()
    max_y, max_x = getmaxyx( stdscr )
    move( max_y/2, max_x/2 )
    addstr("@")
    #addstr(str(getmaxyx(stdscr)))
    getch()
    endwin()
    return 0
if __name__ == "__main__" :
    main()

エラーが発生し続けました

ctypes.ArgumentError was unhandled by user code
Message: argument 2: <class 'TypeError'>: Don't know how to convert parameter 2

この行の場合:

move( max_y/2, max_x/2 )

このエラーの原因と修正を知っている人はいますか。ありがとう!

4

1 に答える 1

0

問題は、関数に浮動小数点数を渡しているのにmove、整数を渡す必要があることです。//の代わりに整数除算演算子を使用し/ます。

from unicurses import *
def main():
    stdscr = initscr()
    max_y, max_x = getmaxyx( stdscr )
    move( max_y//2, max_x//2 ) # Use integer division to truncate the floats
    addstr("@")
    getch()
    endwin()
    return 0
if __name__ == "__main__" :
    main()
于 2015-12-23T15:15:41.823 に答える