2015-09-20 45 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