【发布时间】:2023-03-08 17:10:02
【问题描述】:
你好,我是 python 新手,一直在阅读文档,但在使用 argparse 时遇到问题
这是我正在尝试的代码,请对头脑简单的人进行简单的解释 提前谢谢
#!/usr/bin/env python
import argparse
from string import ascii_lowercase
from string import ascii_uppercase
from string import digits
from string import punctuation
def options():
parser = argparse.ArgumentParser(description="Create a list of characters")
parser.add_argument('-c:')
if (args.c):# == "-c:":
if "-c" + ":" + "caps":
charset = ascii_uppercase
elif "-c:" + "small":
charset = ascii_lowercase
elif "-c:" + "digits":
charset = digits
elif "-c:" + "punc":
charset = punctuation + " "
elif "-c:" + "space":
charset = " "
elif "-c:" + "all":
charset = ascii_lowercase + ascii_uppercase + digits + punctuation + space
else:
print("when using -c you must include an option! (caps, small, digits, punc, space, all)")
def filename():
filename = open('C:\\Users\\MSec\\Desktop\\WordLists\\'+sys.argv[1], 'w')
return
if __name__ == "__main__":
filename()
options()
我还是新手,不太了解文档
我猜想,有没有更好(或更多 Pythonic)的方式来编码所有选项而不是许多 elif 语句?
谢谢大家
【问题讨论】:
标签: python-3.x argparse