Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在终端中运行python程序并使其显示错误?_Python_Windows - Fatal编程技术网

如何在终端中运行python程序并使其显示错误?

如何在终端中运行python程序并使其显示错误?,python,windows,Python,Windows,我正在用python制作一个没有pygame的游戏,它需要在终端上运行。当我在终端中运行代码时,它会短暂打开,但时间不足以让我看到错误。这是我试图运行的代码的一部分,但它不输出任何内容,而是关闭。这意味着我无法找出我的代码有什么问题。当我通过命令提示符运行它时,它不会给出任何输出或错误 from time import sleep def screenArray(): screen = [] for row in range(40): screenRow = [

我正在用python制作一个没有pygame的游戏,它需要在终端上运行。当我在终端中运行代码时,它会短暂打开,但时间不足以让我看到错误。这是我试图运行的代码的一部分,但它不输出任何内容,而是关闭。这意味着我无法找出我的代码有什么问题。当我通过命令提示符运行它时,它不会给出任何输出或错误

from time import sleep

def screenArray():
    screen = []
    for row in range(40):
        screenRow = []
        for column in range(99):
            screenRow.append("-")
        screen.append(screenRow)
    print(screen)
    return screen

def playerToArray(screen, playercoords):
    x = playercoords[0]
    y = playercoords[1]
    print(screen[x,y])
    screen[x,y] = "O"
    return screen

playercoords = [20,50]
print(playerToArray(screenArray(),playercoords))
sleep(10)

打开terminal/cmd并在其中运行,如果您在其中运行它而不是双击或执行任何操作(例如
python3-m file.py
),cmd/terminal将不会关闭。

这是否回答了您的问题?不幸的是,它在程序运行时保持打开状态,但在程序因错误而结束时仍会自动关闭。我用
sleep(10)
运行程序的方法尝试了类似的方法。我通过双击它来运行程序,但我也在命令提示符下尝试过,但尽管它保持打开状态,但它不会给出任何输出或任何错误。我只是尝试了这个方法,但仍然没有从打印语句或错误中获得任何输出。你知道解决这个问题的办法吗?