pythoncurses

windows-curses not working with an import error


I'm just doing some testing with windows-curses (2.3.0) and I was using this code and it gave me an error. The code and error are below.

Code:

import curses
from curses import wrapper

def main(stdscr):
    stdscr.clear()
    stdscr.addstr("Hello World")
    stdscr.refresh()
    stdscr.getch()

wrapper(main)

Error:

Traceback (most recent call last):
  File "C:\Users\norbe\OneDrive\Desktop\Projects\Testing\Curses\curses.py", line 1, in <module>
    import curses
  File "C:\Users\norbe\OneDrive\Desktop\Projects\Testing\Curses\curses.py", line 2, in <module>
    from curses import wrapper
ImportError: cannot import name 'wrapper' from partially initialized module 'curses' (most likely due to a circular import) 

Solution

  • The code already imported curses and its context (methods and variables) binded to it. It means that wrapper is already identified by python.

    Try this :

    import curses
    wrapper = curses.wrapper