返回AttributeError的游标:“module”对象没有属性“initscr”

2024-04-19 12:05:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在关注Curses programming HowTo on the Python site,但我遇到了一个相当奇怪的问题。

我的代码现在很短,实际上什么都不做,因为这个错误,我无法继续。这是我的代码:

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 (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

但我想那是另一个问题。

为了学习诅咒,我正在逐字逐句地学习教程,但目前它让我做的唯一事情就是使用针对Python:p的诅咒

我在Ubuntu 13.10上运行Python 3.3.2,所以this question与此无关,因为他使用的是Windows,而我没有(谢天谢地:D)

为什么我不能这么做?我直接从Python站点复制它,所以您会认为它可以工作!


Tags: 代码infrompyimportmain错误line
2条回答

mv curses.py someOtherName.py

如果出现相同错误,请尝试删除任何.pyc文件。

在这种情况下应该是rm curses.pyc

您命名了文件curses.py,因此Python认为该文件是curses模块。换个名字。

相关问题 更多 >