2

So I do have curses installed Ive checked it with dpkg. Now when I try to import it, this happens

Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import curses
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "curses.py", line 3, in <module>
    myscreen = curses.initscr()
AttributeError: 'module' object has no attribute 'initscr'

I have no idea why it happens - I first tried to run this:

import curses

myscreen = curses.initscr()
myscreen.border(0)
myscreen.addstr(12, 25, "Python curses in action!")
myscreen.refresh()
myscreen.getch()

curses.endwin()

Since I tried it, this happens. Anyone got an idea?

4

1 回答 1

9
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "curses.py", line 3, in <module>

看来您命名了自己的文件 curses.py,Python 首先在当前目录中查找,因此您不能与库同名。

于 2013-04-21T23:01:07.733 回答