0

I have an error in a snake game project when I run the project this message appear "Redirection is not supported".

enter image description here

import random
import curses

s = curses.initscr() 
curses.curs_set(0)
sh, sw = s.getmaxyx()
w = curses.newwin(sh, sw, 0, 0)
w.keypad(1)
w.timeout(100)

snk_x = sw/4
snk_y = sh/2
snake = [
[snk_y, snk_x],
[snk_y, snk_x-1],
[snk_y, snk_x-2]
]

food = [sh//2, sw//2]
w.addch(food[0], food[1], curses.ACS_PI)

key = curses.KEY_RIGHT

while True:
next_key = w.getch()
key = key if next_key == -1 else next_key

if snake[0][0] in [0, sh] or snake[0][1] in [0, sw] or snake[0] in snake[1: ]:
    curses.endwin()
    quit()

    new_head = [snake[0][0], snake[0][1]]

    if key == curses.KEY_DOWN:
        new_head[0] += 1
    if key == curses.KEY_UP:
        new_head[0] -= 1
    if key == curses.KEY_RIGHT:
        new_head[0] -= 1
    if key == curses.KEY_UP:
        new_head[0] += 1

    snake.insert(0, new_head)

    if snake[0] == food:
        food = None
        while food is None:
            nf = [
                random.randint(1, sh-1),
                random.randint(1, sw-1)
            ]
            food = nf if nf not in snake else None
            w.addch(food[0], food[1], curses.ACS_PI)
        else:
            tail = snake.pop()
            w.addch(tail(0), tail(1), ' ')
            w.addch(snake[0][0], snake[0][1], curses.ACS_CXB)
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • Hello Ahmad and welcome to Stackoverflow. please take a moment and read this article https://stackoverflow.com/help/how-to-ask about how to asking questions also read this article https://stackoverflow.com/help/minimal-reproducible-example about how to ask a good question with minimum requirement. – nima Aug 12 '21 at 14:23
  • 1
    don't use a snapshot image in your question, use code snippet in text format (which can be easily copied from your IDE) – nima Aug 12 '21 at 14:24
  • Looks more like a problem with Python itself, not that program. Try running a minimum program, e.g. a file with just `print("hello world")` or even just an empty `py` file. – tobias_k Aug 12 '21 at 14:35
  • That warning at the top of the editor is interesting; maybe there's a change in text-direction from left-to-right to right-to-left somewhere in the file that Python can not handle? What happens if you click "Choose direction"? – tobias_k Aug 12 '21 at 14:37
  • `curses` requires a real terminal for output - apparently the output pane in your IDE is not fully-functional enough to support it. Try running your script directly in a terminal. – jasonharper Aug 12 '21 at 14:41
  • Does this answer your question? [Python curses Redirection is not supported](https://stackoverflow.com/questions/16740385/python-curses-redirection-is-not-supported) – blackbrandt Aug 12 '21 at 15:16
  • Thank you so much guys for your time and your advice, you are really helpful, I appreciate your efforts, and sorry for the bad way of my question but I am a new beginner member in the programming world and in stack over flow too – Ahmad Mahmoud Aug 16 '21 at 04:34

0 Answers0