Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curses returning AttributeError: 'module' object has no attribute 'initscr'

Tags:

python

curses

I am following the Curses programming HowTo on the Python site, but I am running into a rather bizarre issue.

My code is currently very short, doesn't actually do anything because of this error, I haven't been able to move on. Here's my code:

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)

and the 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'

I commented out the from curses import wrapper because that was giving me another error,

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

but I suppose that would be another question.

I am following the tutorial word for word right now, to learn curses, but currently the only thing it's making me do is use curses directed at Python :P.

I am running Python 3.3.2 on Ubuntu 13.10, so this question has nothing to do with this, as he was using Windows and I am not (thankfully :D)

Why am I not able to do this? I'm copying it directly from the Python site, so you'd think it would work!

like image 957
RPiAwesomeness Avatar asked Feb 22 '14 13:02

RPiAwesomeness


1 Answers

You named your file curses.py, so Python thinks that file is the curses module. Name it something else.

like image 192
user2357112 supports Monica Avatar answered Oct 15 '22 04:10

user2357112 supports Monica