TypeError:*之后的encrypt()参数必须是序列,而不是NoneType

时间:2016-02-28 22:01:33

标签: python arguments

有人可以帮我解释为什么会出现这种TypeError吗?

这是check_args函数定义:(此代码基于Owens Stephens AES代码)

def check_args():
    try:
        if (len(sys.argv) != 4):
            raise Exception()
        elif (not os.path.isfile(sys.argv[1])):
            raise Exception("Input file must exist")
        elif (not sys.argv[3] in ['CBC', 'ECB']):
            raise Exception("Block cipher mode should be ECB or CBC")
            return (sys.argv[1], sys.argv[2], sys.argv[3])
    except Exception as ex:
        print ("Usage:", sys.argv[0], "full_path_to_input_image full_path_to_output_image ECB|CBC")
        if len(ex.args) > 0:
            print ("--" + str(ex))
            sys.exit(1)



if __name__ == "__main__":
    args = check_args()
    encrypt(*args)

    Traceback (most recent call last):
       File "  ", line 57, in <module>
       encrypt(*args)
    TypeError: encrypt() argument after * must be a sequence, not NoneType

1 个答案:

答案 0 :(得分:0)

return语句缩进了一个级别太多。 Dedent it。