Python: is there a C-like for loop available? -


Can I do something in Python? (I = L; i; ++) for

 : if some condition: i + = 1 print I  

me Depending on the condition, some values ​​should be able to quit

Edit: All solutions suggest sorting the initial range in one way or another, based on the condition already known to date. This is not useful for me, so let me explain what I want to do.

I want to parse some CMD line abigrants manually (i.e. no depot), where there are certain parameters in each 'keyword', something like this: in category i (0, len (argv ) Arg == 'arg ==' --flag1 ': opt1 = argv [i + 1] i + = 1 if arg ==' - if arg == '- arg = argv [i] for

 : arg = argv [i] -otherother ': optX = argv [i + 1] opty = argv [i + 2] optZ = argv [i + 3] i + = 3 release ...   

You can do two things to solve your problem:

  • Separated with a comma So Con require that being grouped in value following options, you can use getopt , or you can use a different module.
  • Or more delicate your resources:

      sys.argv.pop () CMD = {} while sys.argv: arg = sys.argv.pop (0) If arg == '--arg1': CMD [RG] = sys.argv.pop (0), sys.argv.pop (0) Alif: Pass print (CMD)  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -