hello im new to python and have been reading over the documentation and am having trouble with argparse
here is the code i am trying it onsimple explanation for a simple minded person please
thanks in advance
#!/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()
again im new didnt quite understand the documentation
i guess while im at it is there a better ( or more pythonic) way to code all the options instead of many elif statements?
thanks everyone
All your if statements are always true.
Means
The string “-c:caps” is non-false. The same goes for the rest of the similar if-statements.
You probably mean
And no, there is often no better way that a long list of elifs. There are other ways, but this is the easiest to write and understand, and hence the best.
In this case, however, you can make a dictionary:
And use it like so: