argparse
2020-04-08 本文已影响0人
ThompsonHen
import argparse
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-n", "--name", default="He")
parser.add_argument("-g", "--gender", default="man")
parser.add_argument("-a", "--age", default="20")
print(parser)
args = parser.parse_args()
name = args.name
gender = args.gender
age = args.age
print('I am {}, my gender is {}, I am {} years old'.format(name, gender, age))
if __name__ == "__main__":
main()
image.png