简体   繁体   English

没有 Output 来自 Shell 使用 Python 程序

[英]No Output from a Shell using a Python program

Hello I wrote a Quicksort program which is getting text files as Input.您好,我编写了一个快速排序程序,该程序将文本文件作为输入。 My problem starts when I use a Shell and want to run the program.当我使用 Shell 并想要运行程序时,我的问题就开始了。 I'm not getting an Output or any Error Code.我没有收到 Output 或任何错误代码。 I tried everything but I can't to make my code work.我尝试了一切,但我无法让我的代码正常工作。

import sys

testfile = open(sys.argv[len(sys.argv)-1]
array = testfile.readline()

def Quick_Sort(array, first= 0, last=len(array)-1):
    
    def Partition(array, anf, last):
        Pivot_index = anf
        Pivot = array[Pivot_index]
    
        while anf < last:
            while anf < len(array) and array[anf] <= Pivot:
                anf += 1
            
            while array[last] > Pivot:
                last -= 1
            
            if anf < last:
                array[anf], array[last] = array[last], array[anf]
            
        array[last], array[Pivot_index] = array[Pivot_index], array[last]
        
        return last

    if first < last:
        
        p = Partition(array, first, last)
        
        Quick_Sort(array, first, p-1)
        Quick_Sort(array, p+1, last)
    
    return(array)

Quick_Sort(array)

I stored the text files in a folder "test1" and my program in a folder "py" with an info.txt file, which contains the run command (in my case Run: python quick1.py).我将文本文件存储在文件夹“test1”中,并将我的程序存储在文件夹“py”中,其中包含一个包含运行命令的 info.txt 文件(在我的例子中运行:python quick1.py)。 Like this像这样

例子

示例 2

示例 3

Now when I use a Shell(in my case PuTTy) and do the following:现在,当我使用 Shell(在我的情况下为 PuTTy)并执行以下操作时: 在此处输入图像描述

I don't get an Output.我没有得到 Output。 I am really lost and I don't know where I did something wrong.我真的很迷茫,我不知道我做错了什么。 Any suggestions?有什么建议么?

Well, what output have you expected?那么,你期待什么 output 呢? Since you didn't print() anything the program had executed itself and it didn't return any problem.由于您没有 print() 程序自行执行的任何内容,因此它没有返回任何问题。 You sorted (I assume you did, I didn't check whether it is good algorithm or not) the list and that's all.您对列表进行了排序(我假设您这样做了,我没有检查它是否是好的算法),仅此而已。

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

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