Sign in to follow this  

For Statment Question

Recommended Posts

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

def main(argv):                          
   grammar = "kant.xml"                
   except getopt.GetoptError:          
   for opt, arg in opts:                
       if opt in ("-h", "--help"):      
       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

Share this post

Link to post
Share on other sites

opts is probably a list of pairs, e.g. [('foo', 'bar'), ('baz', 'fnord')].

Edited by jcl

Share this post

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.

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.

Sign in to follow this