For Statment Question


Recommended Posts

I am trying to figure out what is happening in the following code

def main(argv):                          
   grammar = "kant.xml"                
   try:                                
   except getopt.GetoptError:          
       usage()                        
       sys.exit(2)                    
   for opt, arg in opts:                
       if opt in ("-h", "--help"):      
           usage()                    
           sys.exit()                  
       elif opt == '-d':                
           global _debug              
           _debug = 1                  
       elif opt in ("-g", "--grammar"):
           grammar = arg

in particular this line

for opt, arg in opts:

when ever I try to use similar syntax in my python interpreter I get this error

>>> opts = ['j','h','f']
>>> for i, y in opts:
...  print i
...
Traceback (most recent call last):
 File "<stdin>", line 1, in ?
ValueError: need more than 1 value to unpack

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...