简体   繁体   English

如何阻止我的 Python 诅咒代码中发生的错误?

[英]How to stop the error occuring in my Python curses code?

I'm confused about why this error keeps popping up whenever I run some curses code.我很困惑为什么每当我运行一些诅咒代码时都会弹出这个错误。

Code:代码:

import curses

stdscr = initscr()

Output: Output:

Traceback (most recent call last):
  File "C:\Users\Abd-ur-Rahmaan\Desktop\Abd-Ur-Rahmaan Shabbir\Python coding\Python Advanced Shit\The first curses project\The first curses project.py", line 3, in <module>
    stdscr = curses.initscr()
  File "C:\Users\Abd-ur-Rahmaan\Desktop\lib\curses\__init__.py", line 30, in initscr
    fd=_sys.__stdout__.fileno())
AttributeError: 'NoneType' object has no attribute 'fileno'

The Windows version of Python doesn't include the curses module. Python 的 Windows 版本不包括 curses 模块。 A ported version called UniCurses is available.有一个名为 UniCurses 的移植版本可用。 You could also try the Console module written by Fredrik Lundh, which doesn't use the same API as curses but provides cursor-addressable text output and full support for mouse and keyboard input.您还可以尝试 Fredrik Lundh 编写的 Console 模块,它不使用与 curses 相同的 API,但提供光标可寻址文本 output 并完全支持鼠标和键盘输入。

Refer to: https://docs.python.org/3/howto/curses.html参考: https://docs.python.org/3/howto/curses.html

put your.py file wherever you have PATH enabled (it should be the python folder as standart)将 your.py 文件放在启用了 PATH 的任何位置(它应该是 python 文件夹作为标准)

pip install windows-curses pip 安装 windows-curses

right click on start > run右键单击开始>运行

enter the name of the file (snake.py for example)输入文件名(例如snake.py)

run

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM