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 3304702
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:05:24+00:00 2026-05-17T21:05:24+00:00

I would like to have the ability to pass an argument w/o having to

  • 0

I would like to have the ability to pass an argument w/o having to specify an option for optparse. If I do pass an option, it has to be a known option or else the script will fail.

Rsync the following file to destination

myscript.py filename

Rsync the following folder to destination (all this is figured out in function I create).

myscript.py -f foldername

The reason is, I have an array (or dict) that ties with the “foldername.” If no options are passed, the argument given in the CLI is a file that’s in the working folder where the user calls the script. Passing -f means to upload a folder whose value is stored in a dict (user can be in any directory, this folder’s path is known ahead of time).

Am I better off adding options for both options? -f for file and -v for folder aka version?

  • 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-17T21:05:25+00:00Added an answer on May 17, 2026 at 9:05 pm

    I am always a fan of being explicit, but you can short circuit optparse.

    # args[0] is always the executable's name
    if len(args) > 1:
        parser.parse_args(args, options)
    else:
        #open file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is Delphi have any ability to write script of IDE actions? I would like
In php, I would like to have the ability to re-order an associative array
I have a sample dataform and I would like to remove the ability to
So in my project i would like have a nice treeview that has images.
I would like to have the ability to process Win32 messages in a console
I've got a spring roo project and I would like to have the ability
I would like to have the ul ul sub menu have the ability to
I have a C# library that would like to have the ability to Send/Post
Using POCO and Fluent NHibernate, I would like to have the ability to take
I would like to have one view called Example and have the ability to

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.