Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7683347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:46:18+00:00 2026-05-31T18:46:18+00:00

hello im new to python and have been reading over the documentation and am

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:46:19+00:00Added an answer on May 31, 2026 at 6:46 pm

    All your if statements are always true.

    if "-c" + ":" + "caps":
    

    Means

    if "-c:caps":
    

    The string “-c:caps” is non-false. The same goes for the rest of the similar if-statements.

    You probably mean

    if args.c == 'caps':
    

    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:

    CHAR_OPTIONS = {'caps': ascii_uppercase,
                    'small': ascii_lowercase,
                    etc....
                   }
    

    And use it like so:

    charset = CHAR_OPTIONS[args.c]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am a new user to Python and I am having problem doing
Hello I am new at Haskell and i'm having problems trying to get this
Hello I am new to python and have a question about the best/pythonic way
Hello only have a few hours with Java. (from Python) I am trying to
Hello.Am new to ios development.What have to do for NSOpenPanel to work in the
Hello I am new to Git and trying to setup server part and client
I'm new to Google Apps and I've been messing around with the hello world
So I have been having a hard time sending email from my school's email
i'm new to python , and trying to write a script in order to
I have some python code for Google App Engine that responds with the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.