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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:37:21+00:00 2026-05-13T11:37:21+00:00

I am trying to pass ‘-f nameoffile’ to the program when I call it

  • 0

I am trying to pass ‘-f nameoffile’ to the program when I call it from the command line. I got this from the python sites documentation but when I pass ‘-f filename’ or ‘–file=filename’ it throws the error that I didnt pass enough arguments. If i pass -h the programs responds how it should and gives me the help. Any ideas? I imagine its something simple that I am overlooking. Any and all help is great, thanks, Justin.

[justin87@el-beasto-loco python]$ python openall.py -f chords.tar 
Usage: openall.py [options] arg

openall.py: error: incorrect number of arguments
[justin87@el-beasto-loco python]$ 


#!/usr/bin/python

import tarfile
import os
import zipfile
from optparse import OptionParser

def check_tar(file):
    if tarfile.is_tarfile(file):
        return True

def open_tar(file):
    try:
        tar = tarfile.open(file)
        tar.extractall()
        tar.close()
    except tarfile.ReadError:
        print "File is somehow invalid or can not be handled by tarfile"
    except tarfile.CompressionError:
        print "Compression method is not supported or data cannot be decoded"
    except tarfile.StreamError:
        print "Is raised for the limitations that are typical for stream-like TarFile objects."
    except tarfile.ExtractError:
        print "Is raised for non-fatal errors when using TarFile.extract(), but only if TarFile.errorlevel== 2."

def check_zip(file):
    if zipfile.is_zipfile(file):
        return True

def open_zip(file):
    try:
        zip = zipfile.ZipFile(file)
        zip.extractall()
        zip.close()
        #open the zip

        print "GOT TO OPENING"
    except zipfile.BadZipfile:
        print "The error raised for bad ZIP files (old name: zipfile.error)."
    except zipfile.LargeZipFile:
        print "The error raised when a ZIP file would require ZIP64 functionality but that has not been enabled."

rules = ((check_tar, open_tar),
         (check_zip, open_zip)
         )

def checkall(file):           
    for checks, extracts in rules:
        if checks(file):
            return extracts(file)

def main():
    usage = "usage: %prog [options] arg"
    parser = OptionParser(usage)
    parser.add_option("-f", "--file", dest="filename",
                      help="read data from FILENAME")

    (options, args) = parser.parse_args()
    if len(args) != 1:
        parser.error("incorrect number of arguments")

    file = options.filename
    checkall(file)

if __name__ == '__main__':
    main()
  • 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-13T11:37:21+00:00Added an answer on May 13, 2026 at 11:37 am

    Your input filename isn’t an option to the program, it’s an argument:

    def main():
        usage = "Usage: %prog [options] FILE"
        description = "Read data from FILE."
        parser = OptionParser(usage, description=description)
    
        (options, args) = parser.parse_args()
        if len(args) != 1:
            parser.error("incorrect number of arguments")
    
        file = args[0]
        checkall(file)
    

    You can usually tell the difference because options generally have sensible defaults while arguments don’t.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to pass a mono threaded program to multithread. This software do
I am trying to pass a dataString to to an ajax call using JQuery.
I'm trying pass in a url as a paramter to my controller like this:
Trying to pass some values into an imagebutton click event, something like this: <asp:ImageButton
im trying to pass back from a user control a list of strings that
Im trying to pass multiple things from a webpage inside a UIWebView back to
im trying to pass new query to FlexiGrid using this code: $('#fgAllPatients').flexReload({ query: 'blah=qweqweqwe'
I'm trying to pass a value from a select input control on an HTML
I'm trying to pass an element's id to storePair $(#someid).click(storePair($(this).val(),$(this).attr(id)); using $(this) doesn't work.
I am trying to pass an array of interfaces from C# to C++/CLI. Here

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.