0

Background:

Whenever I run s = curses.initscr() in IDLE, I get this error message:

  File "C:/Users/jacob/AppData/Local/Programs/Python/Python37-32/screentest.py", line 3, in <module>
    s = curses.initscr()
  File "C:\Users\jacob\AppData\Local\Programs\Python\Python37-32\lib\curses\__init__.py", line 30, in initscr
    fd=_sys.__stdout__.fileno())
AttributeError: 'NoneType' object has no attribute 'fileno'

This is the message from PyCharm:


Redirection is not supported.

Process finished with exit code 1

And when I run a sample snippet from DevDungeon,


print("Preparing to initialize screen...")
screen = curses.initscr()
print("Screen initialized.")
screen.refresh()

curses.napms(2000)
curses.endwin()

print("Window ended.")

in command prompt with python booted, it just gives an uninteractable blank screen.

Is the thing happening in shell correct?

What the hell is going on?

How can I fix this?

please help thank you

1 Answers1

0

sys.__stdout__ is the original sys.stdout for a python process. When you start python with pythonw.exe, which only exists on Windows, python initially executes stdout = __stdout__ = None. (I am not sure about what happens on *nix.) pythonw.exe is used to run python with a GUI UI without an associated text console. On Windows, the IDLE icons and Start menu entries run python with pythonw. Same with other GUI IDEs.

curses runs with text terminals or consoles. It assumes that sys.__stdout__ is such. It cannot work when sys.__stdout__ is None.

If you start IDLE from a command line terminal/console with python -m idlelib, sys.__stdout__ will be that terminal, and it will have a fileno(). What will happen after that I do not know. If your program uses curses, you are likely better off to run it in the text console.

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52