2015-09-20 76 views
0

我測試出來蟒蛇詛咒模塊和試圖一個簡單的腳本我遇到這個錯誤:詛咒在Python2.7.10/3.4.3 addstr()錯誤

NameError: global name 'addstr' is not defined

這裏是我的代碼:

#!/usr/bin/env python 

import curses, sys 
from curses import * 

def main(): 

    stdscr = initscr() 

    addstr("Hello") 

    endwin() 

if __name__ == "__main__": 
    main() 

我不知道我做了什麼新手的錯誤,我遵循python的curses指南。 在此先感謝。

回答

0

您需要致電addstr()stdscr,因爲這是窗口對象。下面是一個詛咒應用的一個例子:

import curses 
import time 

stdscr = curses.initscr() 
curses.noecho() 
curses.cbreak() 

stdscr.addstr("Hello World") 
stdscr.refresh() 

try: 
    while True: 
     time.sleep(0.001) 
except KeyboardInterrupt: 
    pass 

curses.nocbreak() 
curses.echo() 
curses.endwin() 

注意,while環爲單純,直到你按下Ctrl-C顯示詛咒終端,否則你不會真正看到了。

+0

哇,我是一個真正的假人!我想我沒有注意......謝謝! – Dindan