如何存储参数?

问题描述 投票:0回答:1

程序将存储来自 get_args() 函数的参数,以便在主函数中使用它。 get_args() 函数获取参数并打印它。我无法获取主要函数的参数。

import argparse

def get_args():
     parser = argparse.ArgumentParser(
     prog='Program Name goes here',
     description='What the program does goes here',
     epilog='Text at the bottom of help')
     parser.add_argument('password')          
     args = parser.parse_args()
input = (get_args)
     
  



def main():
     print(input)
 
if __name__ == '__main__' :
    main()
python scripting arguments
1个回答
0
投票

您可以将所有内容合并为一段代码:

import argparse


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        prog='Program Name goes here',
        description='What the program does goes here',
        epilog='Text at the bottom of help')
    parser.add_argument('password')
    args = parser.parse_args()
    print(args)
© www.soinside.com 2019 - 2024. All rights reserved.