我正在遵循Python网站上的Curses编程HowTo,但是我遇到了一个非常奇怪的问题。
我的代码目前非常简短,实际上什么都没做,由于这个错误,我无法继续。这是我的代码:
我注释掉了
但我想这可能是另一个问题。我现在逐字地按照教程学习curses,但目前它唯一让我做的就是使用针对Python的curses :P。我在Ubuntu 13.10上运行Python 3.3.2,所以这个问题与此问题无关,因为他使用的是Windows,而我不是(谢天谢地:D)。为什么我不能做到这一点?我直接从Python网站复制,所以你会认为它应该能工作!
我的代码目前非常简短,实际上什么都没做,由于这个错误,我无法继续。这是我的代码:
import curses
#from curses import wrapper
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(True)
def main(stdscr):
begin_x = 20; begin_y = 7
height = 5; width = 40
win = curses.newwin(height, width, begin_y, begin_x)
stdscr.refresh()
stdscr.getkey()
if __name__ == '__main__':
wrapper(main)
和 Traceback:
Traceback (most recent call last):
File "curses.py", line 1, in <module>
import curses
File "/home/nate/Documents/Programming/Python/curses.py", line 4, in <module>
stdscr = curses.initscr()
AttributeError: 'module' object has no attribute 'initscr'
我注释掉了
from curses import wrapper
,因为这会给我带来另一个错误。Traceback (most recent call last):
File "curses.py", line 1, in <module>
import curses
File "/home/nate/Documents/Programming/Python/curses.py", line 2, in <module>
from curses import wrapper
ImportError: cannot import name wrapper
但我想这可能是另一个问题。我现在逐字地按照教程学习curses,但目前它唯一让我做的就是使用针对Python的curses :P。我在Ubuntu 13.10上运行Python 3.3.2,所以这个问题与此问题无关,因为他使用的是Windows,而我不是(谢天谢地:D)。为什么我不能做到这一点?我直接从Python网站复制,所以你会认为它应该能工作!
curses.pyc
的文件,并将其删除。 - Jack M