程序将存储来自 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()
您可以将所有内容合并为一段代码:
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)