Python: is there a C-like for loop available?
Yes, this is how I would do it
>>> for i in xrange(0, 10):
... if i == 4:
... continue
... print i,
...
0 1 2 3 5 6 7 8 9
EDIT
Based on the update to your original question... I would suggest you take a look at optparse
There are two things you could do to solve your problem:
- require comma-separated arguments which are going to be grouped into the following option value, you could use
getopt
, or any other module then. or do more fragile own processing:
sys.argv.pop() cmd = {} while sys.argv: arg = sys.argv.pop(0) if arg == '--arg1': cmd[arg] = sys.argv.pop(0), sys.argv.pop(0) elif: pass print(cmd)
for (i = 0; i < 10; i++)
if someCondition:
i+=1
print i
In python would be written as
i = 0
while i < 10
if someCondition
i += 1
print i
i += 1
there you go, that is how to write a c for loop in python.
Strange way:
for x in (x for x in xrange(10) if someCondition):
print str(x)