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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:57:45+00:00 2026-05-14T03:57:45+00:00

For some code as follows, opts, args = getopt.getopt(sys.argv[1:], c:, … for o,v in

  • 0

For some code as follows,


opts, args = getopt.getopt(sys.argv[1:], “c:”, …
for o,v in opts:
…
elif o in (“-c”, “–%s” % checkString):
kCheckOnly = True
clientTemp = v

If I don’t give the parameter after the -c, I get the error messages as follows.


Traceback (most recent call last):
File “niFpgaTimingViolationMain.py”, line 100, in
opts, args = getopt.getopt(sys.argv[1:], “hdc:t:”,[helpString, debugString, checkString, twxString])
File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/getopt.py”, line 91, in getopt
opts, args = do_shorts(opts, args[0][1:], shortopts, args[1:])
File “/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/getopt.py”, line 195, in do_shorts
opt)
getopt.GetoptError: option -c requires argument

Is there any way to catch this error, and process it to print something like this? It seems that just wrapping the code in try/except doesn’t work.


ERROR: You forgot to give the file name after -c option

  • 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-14T03:57:45+00:00Added an answer on May 14, 2026 at 3:57 am

    You can catch getopt.GetoptError and check the ‘opt’ and ‘msg’ attributes yourself:

    try:
        opts, args = getopt.getopt(sys.argv[1:], "c:", ...
    except getopt.GetoptError, e:
        if e.opt == 'c' and 'requires argument' in e.msg:
            print >>sys.stderr, 'ERROR: You forgot to give the file name after -c option'
            sys.exit(-1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I have some code as follows template<typename Type> Type* getValue(std::string name, bool tryUseGetter
Here's some code (full program follows later in the question): template <typename T> T
When I reading the code of CodeIgniter,I found some functions written as follows: function
I have some code as follows: $query = <<<QUERY SELECT * FROM names WHERE
My code is as follows: sub main() '''some more code''' For j = InStr(1,
I've written some code to handle an event as follows: AddHandler myObject.myEvent, AddressOf myFunction
I have some code as follows var MyObjectInstance = httpContext.Items[key] as MyObject What overhead
I have some code as follows: <f:loadBundle basename=messages.application var=prop /> <ui:param name=currentUserAttr value=#{prop['currentUser']} />
I have some java code as follows: try { String outString =java -jar C:\\ami\\bin\\ImmediateSubmit.jar
I have some code defined as follows: typedef long (*ShellExecFunct)(long, const char*, const char*,

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.